Solved

calling WMI from asp

Posted on 2006-07-24
3
317 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
[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
  • 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

Technology Partners: 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 recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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