Solved

calling WMI from asp

Posted on 2006-07-24
3
301 Views
Last Modified: 2012-05-05
experts this is my third post involving this proble. basically, all i want to do is to be able to restart (or stop and start) a service on a server from a web page. I have found the code bellow which will do this for me, if only I could get it working. I get the following error when I try and run the page:

Error Type:
(0x80041003)
/battest/betest3.asp, line 21

this is where I make a call to the winmgmts object.

I am just trying to run this locally at the moment, and have given Everyone full control on my pc just to see if I can get it working.

can someone please help me. I am desperate to get this resolved, hence the points.

here is the code I am using:

<%
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer, strService, intSleep, WScript
strComputer = "localhost"
intSleep = 15000

Set WScript = server.CreateObject("wscript.shell")
Response.Write " Click OK, then wait " & intSleep & " milliseconds"

'On Error Resume Next
' NB strService is case sensitive.
strService = " 'Alerter' "
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery _
("Select * from Win32_Service Where Name ="_
& strService & " ")

For Each objService in colListOfServices
    objService.StopService()
    WSCript.Sleep intSleep
    objService.StartService()
Next
Response.Write "Your "& strService & " service has Started"
WScript.Quit
' End of Example WMI script to Start / Stop services
      
%>


thanks in advance for any help
0
Comment
Question by:telliot79
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
joeposter649 earned 500 total points
ID: 17170586
0
 

Author Comment

by:telliot79
ID: 17171483
nope,

amazingly enough, I had searched the rest of the web, but not MSDN, or atleast not to this page on the MSDN site.

Thanks joeposter649, I will post my final code when I have pieced it all together.
0
 

Author Comment

by:telliot79
ID: 17172002
uncheck anonymous access in IIS for this file, or the folder where this file resides and all should be gtg


<%
Option Explicit
Dim objWMIService, objItem, objService, strServiceList
Dim colListOfServices, strComputer, strService, optionList
Dim colServices, strMessage, colService

strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service ")

For Each objService in colListOfServices
      optionList = optionList & "<OPTION value=" & chr(34) & objService.name & chr(34)
      if request("ddService") = objService.name then
            optionList = optionList & " selected"
            objService.StopService()
            objService.StartService()
            strMessage = "The Service '" & objService.name & "' has been stopped and started "
      end if
      optionList = optionList & ">" & objService.name & "</OPTION>"
Next

%>


<html>
<head>
      <title>Service Restart</title>
</head>
<form name="form1" method="post" action="kickstart.asp" ID="Form1">
<body>
<table border="0" cellpadding="0" cellspacing="0">
      <tr>
            <td valign=middle><SELECT  NAME="ddService" class="normaltext" ID="Select1">
                        <option value=""> -- SELECT -- </option>
                        <%=optionList%>
                  </SELECT><br>
            </td>
            <td align="center"><INPUT type="Submit" NAME="btnSubmit" value="Restart" ID="Submit1"></td></tr>
      <tr><td colspan="2"><br><%=strMessage%></td></tr>
</table>
</form>
</body>
</html>

            
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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 information …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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