Solved

Using a VBS within ASP Page

Posted on 2003-11-07
11
380 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
  • 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now