?
Solved

calling WMI from asp

Posted on 2006-07-24
3
Medium Priority
?
327 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 2000 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

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!

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…
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month16 days, 5 hours left to enroll

850 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