Solved

calling WMI from asp

Posted on 2006-07-24
3
312 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 100
Obtaining data on ASP 8 35
IIS 7 and executing pages using localhost 16 24
href return to normal window 5 28
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…
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/…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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