Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using a VBS within ASP Page

Posted on 2003-11-07
11
Medium Priority
?
389 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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