Solved

Using a VBS within ASP Page

Posted on 2003-11-07
11
387 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

734 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