Solved

Using a VBS within ASP Page

Posted on 2003-11-07
11
386 Views
Last Modified: 2008-02-01
Hi All - What Im trying to do, is use this VBS which I converted to use within VB, to work within ASP so I can allow people to change the state of the Messenger Service via the browser but I don't know if it can be done... Any help would be great!

Set wbemservices = GetObject("winmgmts:\\.")
Set wbemObject = wbemservices.Get("Win32_Service.Name='Messenger'")
Wscript.echo "Display Name: " & wbemObject.DisplayName & vbCrlf _
     & vbTab & "State: " & wbemObject.State & vbCrlf _
     & vbTab & "StartMode: " & wbemObject.StartMode & vbCrlf _

Select Case wbemObject.StartMode
     Case "Boot"
     Case "System"
     Case "Auto"
          Wscript.Echo "Auto"
          wbemObject.ChangeStartMode "Manual"
     Case "Manual"
     Case "Disabled"
End Select

Select Case wbemObject.State
     Case "Stopped"
     Case "Start Pending"
     Case "Stop Pending"
     Case "Running"
          Wscript.Echo "Running"
     Case "Continue Pending"
     Case "Pause Pending"
     Case "Paused"
     Case "Unknown"
End Select
0
Comment
Question by:jilamints
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
11 Comments
 
LVL 21

Expert Comment

by:ap_sajith
ID: 9706252
I cant get the code to work on my side.. but i have converted the code to proper vbscript syntax... so you could give this a try...'

<Script language=vbscript>
Set wbemservices = CreateObject("winmgmts:\\.")
Set wbemObject = wbemservices.Get("Win32_Service.Name='Messenger'")
Wscript.echo "Display Name: " & wbemObject.DisplayName & vbCrlf _
    & vbTab & "State: " & wbemObject.State & vbCrlf _
     & vbTab & "StartMode: " & wbemObject.StartMode & vbCrlf _

Select Case wbemObject.StartMode
     Case "Boot"
    Case "System"
    Case "Auto"
         Wscript.Echo "Auto"
         wbemObject.ChangeStartMode "Manual"
    Case "Manual"
     Case "Disabled"
End Select

Select Case wbemObject.State
    Case "Stopped"
    Case "Start Pending"
    Case "Stop Pending"
    Case "Running"
         Wscript.Echo "Running"
    Case "Continue Pending"
    Case "Pause Pending"
    Case "Paused"
    Case "Unknown"
End Select
</script>

Cheers!!
0
 

Author Comment

by:jilamints
ID: 9706412
I get an error when I try and run it:

ActiveX compon
0
 

Author Comment

by:jilamints
ID: 9706413
Sorry: Again...

ActiveX component can't create object 'winmgmts:\\.'

0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 21

Expert Comment

by:ap_sajith
ID: 9706693
I got the same error. Since i dont have that component installed on my pc, its giving the error. What does the winmgmts component do?. Is it supposed to run client side or server side?. If it is supposed to run client side, make sure that you have the component installed in the client.

If it is server side, the code is going to be slightly differrent.

Cheers!!
0
 

Author Comment

by:jilamints
ID: 9708284
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnclinic/html/scripting08132002.asp

I want this to run on the client side so the user can check the status of the server, then take a certain course of action ?
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 9708943
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=6430F853-1120-48DB-8CC5-F2ABDC3ED314

Read the system requirements and make sure that you have WMI v1.5 installed in the PC from which you are executing the code.

Cheers!!
0
 

Author Comment

by:jilamints
ID: 9708971
Well I'm using Windows 2000 and the server is W2K Adv Server - Now after installing this, I still have the same problems and, my VB version of this, which is basically exactly the same, works perfect... So I don't see how I can get around my little problem ?

Do I make up some ActiveX thing for people to download or what ?
0
 
LVL 21

Accepted Solution

by:
ap_sajith earned 250 total points
ID: 9709022
Why dont you use this piece of server side code to check for server availability....

<%

function isServerAvailable(sURL)
Dim objXMLHTTP                  'Holds the XML HTTP Object

'Create an XML object to query the remote whois server
Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")

'Alternative XML HTTP component, for version 3.0 of XMLHTTP
'Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

'Open a connection to the remote whois server
objXMLHTTP.Open "GET", sURL, False

'Send the request and return the data
objXMLHTTP.Send

If objXMLHTTP.Status=200 Then ' ** IF PAGE HAS BEEN RETRIEVED THEN **
      isServerAvailable=True
Else
      isServerAvailable=False
End If
End Function

response.write isServerAvailable("http://site/test.asp")
%>

Cheers!!
0
 
LVL 21

Expert Comment

by:ap_sajith
ID: 10243488
Hi,
Any Updates?. Do you need any further assistance with this?. Please close this question if no further assistance is needed.
If you need help closing this question, please refer to http://oldlook.experts-exchange.com/help/closing.jsp on how to close a question.

Cheers!!
0
 
LVL 7

Expert Comment

by:vnvk
ID: 11962180
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Accept: ap_sajith {http:#9709022}

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

vnvk
EE Cleanup Volunteer
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question