Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Starting & Stopping services from asp web page

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,64525
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Starting & Stopping services from asp web page
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Starting & Stopping services from asp web page - 9/24/2008 5:39:59 AM   
  kpandya

 

Posts: 3
Score: 0
Joined: 9/24/2008
Status: offline
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
 
 
Post #: 1
 
 RE: Starting & Stopping services from asp web page - 10/7/2008 10:17:07 AM   
  wjcott

 

Posts: 41
Score: 0
Joined: 9/7/2008
Status: offline
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.

(in reply to kpandya)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Starting & Stopping services from asp web page Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts