kpandya
-
Total Posts
:
3
- Scores: 0
-
Reward points
:
0
- Joined: 9/24/2008
-
Status: offline
|
Starting & Stopping services from asp web page
Wednesday, September 24, 2008 6:39 AM
( permalink)
Hi Guys, For an internal project, I am trying to get a webpage to stop and start windows services across servers and seem to be going round in circles. Is this even possible, basically I have attempted to use WMI insdie a asp page to be called when the user clicks on a button, but was having a problem as I guess the button is client side and the code was server side. I then moved the function I created client side and seem to be getting errors: "ActiveX components can't create object: 'GetObject' This is what I have wrote (as I am not a programmer, probably quite messy): <%@ Language="VBScript" %> <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.5 Library" UUID="{00000205-0000-0010-8000-00AA006D2EA4}" VERSION="2.5"--> <html> <head> TEST SERVICE RESTART <% document.write("TEST SERVICE RESTART") %> </head> <body> <script language="VBScript"> Function startservice() dim ObjWMIService, objItem, ObjService dim strComputer, strService, ColListOfServices strComputer = "." strService = "myservice" 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.StartService() Next WScript.Echo "Your "& strService & " service has Started" WScript.Quit End Function </script> <form name="RestartCFD"> <input type="button" value="Restart" name="start" onClick="startservice()"> </form> </body> </html> In trying to resolve this error I found that from a web page SWbem should be used instead of WMI so I re-wrote the script: <%@ Language="VBScript" %> <!--METADATA TYPE="TypeLib" NAME="Microsoft ActiveX Data Objects 2.5 Library" UUID="{00000205-0000-0010-8000-00AA006D2EA4}" VERSION="2.5"--> <html> <head> TEST SERVICE RESTART <% document.write("TEST SERVICE RESTART") %> </head> <body> <script language="VBScript"> Function startservice() dim objSWbemService, objItem, ObjService, objSWbemLocator, colSWbemObjectSet dim strComputer, strService, ColListOfServices strComputer = "10.220.9.125" strService = "iiMM5DummySystemMonitor" Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") Set objSWbemService = objSWbemLocator.ConnectServer("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colSWbemObjectSet = objSWbemService.ExecQuery("Select * from Win32_Service Where Name ='"& strService & "'") For Each objSWbemService in colSWbemObjectSet objSWbemService.StartService() Next End Function </script> <form name="RestartCFD"> <input type="button" value="Restart" name="start" onClick="startservice()"> </form> </body> </html> When running the above I get the error stating - "The RPC server is unavailble" The first script works fine when saved locally as a *.vbs file but I just can't seem to mimic this from a web page. Could someone point me in the right direction as to if I am firstly wasting my time trying to get the above to work or if there is a better way of restarting multiple services across multiple servers from a web page.... Thanks in advance
|
|
|
|
wjcott
-
Total Posts
:
45
- Scores: 0
-
Reward points
:
0
- Joined: 9/7/2008
-
Status: offline
|
RE: Starting & Stopping services from asp web page
Tuesday, October 07, 2008 11:17 AM
( permalink)
Is the web page running under IUSR credentials or are you using Windows authentication for page access? If it is the former,your impersonation may be of either the IUSR or IWAM account.
|
|
|
|