I have been staring at this too long and just not finding what I have wrong here. Can anyone tell me what the problem is? My page displays correctly, but the buttons do not execute the functions. Thanks in advance.
I hope you find this post helpful.
Regards,
Mark
Check out my scripting solutions at
Code:
<%@ LANGUAGE="VBSCRIPT" %>
<%
On Error Resume Next
Dim strComputer
strComputer = "TSPSERVER"
Sub StopService(ServiceName)
Set objWMI = getobject("winmgmts://" & strComputer)
queryString = "select state from win32_service " _
& "where displayname='"& ServiceName & "'"
set results = objWMI.execquery(queryString)
for each service in results
if service.state = "Running" then
service.stopService
end if
next
Response.Redirect "Servicemanagement.asp"
End Sub
Sub StartService(ServiceName)
Set objWMI = getobject("winmgmts://" & strComputer)
queryString = "select state from win32_service " _
& "where displayname='"& ServiceName & "'"
set results = objWMI.execquery(queryString)
for each service in results
if service.state <> "Running" then
service.startService
end if
next
Response.Redirect "Servicemanagement.asp"
End Sub
%>
<html>
<head>
<title>Service Management</title>
</head>
<body bgcolor="#99CCFF" style="text-align: center" link="#000000" vlink="#000000" alink="#99CCFF">
<table width="80%" border="1">
<tr bgcolor="white"><th style="width: 412px">Service</th>
<th style="width: 180px">State</th><th>Action</th></tr>
<tr><td style="width: 412px"></td><td style="width: 180px"></td>
<%
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service",,48)
For Each objItem in colItems
Response.Write "<tr><td>"
Response.Write objItem.DisplayName
Response.Write "</td><td>"
Response.Write objItem.State
Response.Write "</td><td>"
If objItem.State = "Running" Then
Response.Write "<input type='Button' Value='Stop' onclick='StopService(" & objItem.Name & ")'>"
Else
Response.Write "<input type='Button' Value='Start' onclick='StartService(" & objItem.Name & ")'>"
End If
Response.Write "</td></tr>"
Next
%>
</table>
</body>
</html>
I hope you find this post helpful.
Regards,
Mark
Check out my scripting solutions at