Lee025_
asked on
HTA with VBScript to stop/start windows services
Hi all,
I have written a vbscript that queries the services of a local machine then writes the results out to an HTA file. To the right hand side of each listed service is a checkbox. What I want to do is ahve the user select one/multiple checkboxes and hit a start/stop/restart button then it will go off and perform the tasks.
the hta is writing successfully but I don't know how to relate the checkbox to the actual service that needs starting etc.
I'm not worried about being able to stop/start multiple services to start with only one.
Attached is a copy of the HTA code. Excuse the formatting, as it's being dynamically written!
TIA
Lee
I have written a vbscript that queries the services of a local machine then writes the results out to an HTA file. To the right hand side of each listed service is a checkbox. What I want to do is ahve the user select one/multiple checkboxes and hit a start/stop/restart button then it will go off and perform the tasks.
the hta is writing successfully but I don't know how to relate the checkbox to the actual service that needs starting etc.
I'm not worried about being able to stop/start multiple services to start with only one.
Attached is a copy of the HTA code. Excuse the formatting, as it's being dynamically written!
TIA
Lee
<html><head><title>ABL Server Service Checker</title>
<HTA:APPLICATION
ID = "ServiceCheckerApp"
APPLICATIONNAME="Service Check"
BORDER = "thin"
CAPTION = "yes"
RESIZE = "no"
ICON = "Msn-Messenger.ico"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "no"
SYSMENU = "Yes"
WINDOWSTATE = "normal"
SCROLL = "yes"
SCROLLFLAT = "yes"
VERSION = "1.0"
INNERBORDER = "no"
SELECTION = "no"
MAXIMIZEBUTTON = "no"
MINIMIZEBUTTON = "yes"
NAVIGABLE = "yes"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal">
</hta>
<style>
body
{
background-color: #008B8B;
font-family: Helvetica;
font-size: 8pt;
margin-top: 10px;
margin-left: 20px;
margin-right: 10px;
margin-bottom: 10px;
}
TD
{
font-family: Trebuchet MS;
font-size: 8pt;
}
LEGEND
{
font-family: Trebuchet MS;
font-size: 10pt;
}
Select
{
font-family: Trebuchet MS;
font-size: 8pt;
width:195px
}
INPUT
{
font-family: Trebuchet MS;
font-size: 8pt;
}
</style>
<script language="VBScript">
Const ForAppending = 8
oServer = "PC02205"
Sub Window_OnLoad
Dim width, height, x, y
width = 425
height = 700
x = (window.screen.width - width) / 2
y = (window.screen.height - height) / 2
If x < 0 Then x = 0
If y < 0 Then y = 0
window.resizeTo width,height
window.moveTo x,y
End Sub
Sub startService
service = "????"
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & oServer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & service & "'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
Set colServiceList = objWMIService.ExecQuery("Associators of {Win32_Service.Name='" & service & "'} Where AssocClass=Win32_DependentService " & "Role=Dependent" )
For each objService in colServiceList
objService.StartService()
Next
End Sub
Sub restartService
Msgbox "Restart Me"
End Sub
Sub CloseForm
Window.Close
End Sub
</script>
</head><body>
<tr><td align="left" valign="bottom">
<input type="button" value="Start" onclick="StartService" title=" Click to Start the Services">
<input type="button" value="Stop" onclick="StopService" title=" Click to Stop the Service">
<input type="button" value="Restart" onclick="RestartService" title=" Click to Restart the Services">
<input type="button" value=" Exit " onclick="CloseForm" title=" Click to Exit Form ">
<table border="0" cellspacing="0" CellSpacing="0"><tr><td width="350">
<tr><td valign="top" colspan="3"><fieldset><legend><b>Service List</b></legend>
<table border="0" cellpadding="3" width="350">
<TR><TD align='left' bgcolor='#f0f0f0'>Alerter</TD><td bgcolor=#FD0000 align=center><i>Stopped</i></td><td><input type="checkbox" name="Alerter"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Apple Mobile Device</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Apple Mobile Device"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Windows Audio</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Windows Audio"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Bonjour Service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Bonjour Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Computer Browser</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Computer Browser"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>LANDesk(R) Management Agent</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="LANDesk(R) Management Agent"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Citrix Diagnostic Facility COM Server</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Citrix Diagnostic Facility COM Server"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>VMware Capacity Planner Service</TD><td bgcolor=#FD0000 align=center><i>Stopped</i></td><td><input type="checkbox" name="VMware Capacity Planner Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Cryptographic Services</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Cryptographic Services"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>DCOM Server Process Launcher</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="DCOM Server Process Launcher"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>DHCP Client</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="DHCP Client"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Logical Disk Manager</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Logical Disk Manager"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>DNS Client</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="DNS Client"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Event Log</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Event Log"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Fax</TD><td bgcolor=#FD0000 align=center><i>Stopped</i></td><td><input type="checkbox" name="Fax"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>HP Network Devices Support</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="HP Network Devices Support"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>IBM Rapid Restore Ultra Service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="IBM Rapid Restore Ultra Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>IBM User Verification Manager</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="IBM User Verification Manager"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Intel Alert Handler</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Intel Alert Handler"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Intel Local Scheduler Service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Intel Local Scheduler Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Intel PDS</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Intel PDS"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>LANDesk Targeted Multicast</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="LANDesk Targeted Multicast"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>LANDesk Remote Control Service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="LANDesk Remote Control Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Java Quick Starter</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Java Quick Starter"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>LANDesk Policy Invoker</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="LANDesk Policy Invoker"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Server</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Server"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Workstation</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Workstation"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>LANDesk(R) Extended device discovery service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="LANDesk(R) Extended device discovery service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>TCP/IP NetBIOS Helper</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="TCP/IP NetBIOS Helper"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Messenger</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Messenger"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Microsoft Exchange Management</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Microsoft Exchange Management"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Net Logon</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Net Logon"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Plug and Play</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Plug and Play"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>IPSEC Services</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="IPSEC Services"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Protected Storage</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Protected Storage"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Remote Registry</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Remote Registry"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Remote Procedure Call (RPC)</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Remote Procedure Call (RPC)"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Security Accounts Manager</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Security Accounts Manager"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Sophos Anti-Virus status reporter</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Sophos Anti-Virus status reporter"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Sophos Anti-Virus</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Sophos Anti-Virus"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Task Scheduler</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Task Scheduler"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>System Event Notification</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="System Event Notification"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Shell Hardware Detection</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Shell Hardware Detection"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>LANDesk(R) Software Monitoring Service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="LANDesk(R) Software Monitoring Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Print Spooler</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Print Spooler"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Windows Image Acquisition (WIA)</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Windows Image Acquisition (WIA)"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Themes</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Themes"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>OfficeScan NT Firewall</TD><td bgcolor=#FD0000 align=center><i>Stopped</i></td><td><input type="checkbox" name="OfficeScan NT Firewall"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Distributed Link Tracking Client</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Distributed Link Tracking Client"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>VMware Converter Service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="VMware Converter Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Veeam Backup and FastSCP Service</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Veeam Backup and FastSCP Service"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Protector Suite Virtual Token</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Protector Suite Virtual Token"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Windows Time</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Windows Time"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>Windows Management Instrumentation</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="Windows Management Instrumentation"></td>
<TR><TD align='left' bgcolor='#f0f0f0'>VNC Server</TD><td bgcolor=#00CD00 align=center><i>Running</i></td><td><input type="checkbox" name="VNC Server"></td>
</table><p></fieldset></table>
</td></tr></table></td>
<table border="0" cellspacing="0" cellpadding="0" width="350">
<tr><td align="left" valign="bottom">
<input type="button" value="Start" onclick="StartService" title=" Click to Start the Services">
<input type="button" value="Stop" onclick="StopService" title=" Click to Stop the Service">
<input type="button" value="Restart" onclick="RestartService" title=" Click to Restart the Services">
<input type="button" value=" Exit " onclick="CloseForm" title=" Click to Exit Form ">
</td></tr></table></body></html>
ASKER
Great thanks, ill take a look see if I can pull out the relevant code
ASKER
Just had a quick look and can see where the variables are being passed back from the html controls. However my problem is that the controls themselves (in my case check boxes) are written on the fly by a vbscript based on the services installed on the machine chosen. So the list of services could be different every time. I'm not sure how to name/create the check boxes so they can be referenced in relation to the service name to the left of it.
Thanks
Lee
Thanks
Lee
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just what I was after!!! Thanks v much been looking for 2 weeks to find an answer to this problem!
Thanks again
Lee
Thanks again
Lee
Anyway to make this go to a remote pc
I adjusted a few lines to make it easier for you to edit what remote computer the script connect to.
Edit line 15 to match the computer name of the machine you want to see.
Edit line 15 to match the computer name of the machine you want to see.
<head>
<title>Server Services</title>
<HTA:APPLICATION
APPLICATIONNAME="Server Services"
BORDER="thin"
SCROLL="yes"
SINGLEINSTANCE="yes"
ID="oHTA"
>
<APPLICATION:HTA>
</head>
<script language="VBScript">
Dim strcomputer
strcomputer = "Computer-Name-Here"
Sub Window_OnLoad
span_computername.InnerHTML = uCase(strcomputer)
Set objlst_groupnames = document.getElementById( "list_servicenames" )
If objlst_groupnames Is Nothing Then
MsgBox "A problem was encountered while creating the listview." & vbCRLF & "Please see your administrator."
Else
With objlst_groupnames
.View = 3
.Width = 800
.Height = 600
.SortKey = 0
.Arrange = 0
.LabelEdit = 1
.SortOrder = 0
.Sorted = 1
.MultiSelect = 0
.LabelWrap = -1
.HideSelection = -1
.HideColumnHeaders = 0
.OLEDragMode = 0
.OLEDropMode = 0
.Checkboxes = 1
.FlatScrollBar = 0
.FullRowSelect = 1
.GridLines = 0
.HotTracking = 0
.HoverSelection = 0
.PictureAlignment = 0
.TextBackground = 0
.ForeColor = -2147483640
.BackColor = -2147483643
.BorderStyle = 1
.Appearance = 1
.MousePointer = 0
.Enabled = 1
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Caption", 150
.ColumnHeaders.Add , , "State", 150
.ColumnHeaders.Add , , "Name", 150
.ColumnHeaders.Add , , "Description", 150
.ColumnHeaders.Add , , "Start Mode", 150
.ListItems.Clear
End With
End If
ListServices(strcomputer)
End Sub
Sub ListServices(sComputer)
ON ERROR RESUME NEXT
Set objList = document.getElementById( "list_servicenames" )
objList.ListItems.Clear
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objItem in colItems
Set objListItem = objList.ListItems.Add
objListItem.Text = objItem.Caption
objListItem.ListSubItems.Add.Text = objItem.State
objListItem.ListSubItems.Add.Text = objItem.Name
objListItem.ListSubItems.Add.Text = objItem.Description
objListItem.ListSubItems.Add.Text = objItem.StartMode
Next
End Sub
Sub btn_start_onClick()
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
end if
next
ListServices(strComputer)
End Sub
Sub btn_stop_onClick()
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
end if
next
ListServices(strComputer)
End Sub
Sub btn_restart_onClick()
'Stop services
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
end if
next
'Start services
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
end if
next
ListServices(strComputer)
End Sub
Sub btn_Refresh_onClick()
ListServices(strComputer)
End Sub
Sub btn_exit_onClick()
Window.Close
End Sub
function list_servicenames_ColumnClick(colheader)
list_servicenames.SortKey = colheader.index-1
end function
</script>
<body>
You are connected to: <span id="span_computername"> </span><br><br>
<OBJECT id="list_servicenames" name="list_servicenames" classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628"></OBJECT>
<br />
<input type="button" value="Refresh" name="btn_Refresh" id="btn_Refresh" title="Click to refresh the services list">
<input type="button" value="Start" name="btn_start" id="btn_start" title="Click to Start the Services">
<input type="button" value="Stop" name="btn_stop" id="btn_stop" title="Click to Stop the Service">
<input type="button" value="Restart" name="btn_restart" id="btn_restart" title="Click to Restart the Services">
<input type="button" value="Exit" name="btn_exit" id="btn_exit" title="Click to Exit Form ">
</body>
great if I manually plug in pc name it works how can I get it to prompt for pc name?
I added a button near the top to click on. A popup will open for you to type the computer name.
<head>
<title>Server Services</title>
<HTA:APPLICATION
APPLICATIONNAME="Server Services"
BORDER="thin"
SCROLL="yes"
SINGLEINSTANCE="yes"
ID="oHTA"
>
<APPLICATION:HTA>
</head>
<script language="VBScript">
Dim strcomputer
strcomputer = "Computer-Name-Here"
Sub Window_OnLoad
Set objlst_groupnames = document.getElementById( "list_servicenames" )
If objlst_groupnames Is Nothing Then
MsgBox "A problem was encountered while creating the listview." & vbCRLF & "Please see your administrator."
Else
With objlst_groupnames
.View = 3
.Width = 800
.Height = 600
.SortKey = 0
.Arrange = 0
.LabelEdit = 1
.SortOrder = 0
.Sorted = 1
.MultiSelect = 0
.LabelWrap = -1
.HideSelection = -1
.HideColumnHeaders = 0
.OLEDragMode = 0
.OLEDropMode = 0
.Checkboxes = 1
.FlatScrollBar = 0
.FullRowSelect = 1
.GridLines = 0
.HotTracking = 0
.HoverSelection = 0
.PictureAlignment = 0
.TextBackground = 0
.ForeColor = -2147483640
.BackColor = -2147483643
.BorderStyle = 1
.Appearance = 1
.MousePointer = 0
.Enabled = 1
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Caption", 150
.ColumnHeaders.Add , , "State", 150
.ColumnHeaders.Add , , "Name", 150
.ColumnHeaders.Add , , "Description", 150
.ColumnHeaders.Add , , "Start Mode", 150
.ListItems.Clear
End With
End If
if strComputer <> "" then
ListServices(strcomputer)
end if
End Sub
Sub ListServices(sComputer)
ON ERROR RESUME NEXT
Set objList = document.getElementById( "list_servicenames" )
objList.ListItems.Clear
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objItem in colItems
Set objListItem = objList.ListItems.Add
objListItem.Text = objItem.Caption
objListItem.ListSubItems.Add.Text = objItem.State
objListItem.ListSubItems.Add.Text = objItem.Name
objListItem.ListSubItems.Add.Text = objItem.Description
objListItem.ListSubItems.Add.Text = objItem.StartMode
Next
End Sub
Sub btn_start_onClick()
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
end if
next
ListServices(strComputer)
End Sub
Sub btn_stop_onClick()
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
end if
next
ListServices(strComputer)
End Sub
Sub btn_restart_onClick()
'Stop services
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StopService()
Next
end if
next
'Start services
for n = 1 to list_servicenames.ListItems.Count
if list_servicenames.ListItems(n).checked = True then
strService = list_servicenames.ListItems(n).ListSubItems(2).Text
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colServiceList = objWMIService.ExecQuery ("Select * from Win32_Service where Name='" & strService & "'")
For each objService in colServiceList
errReturn = objService.StartService()
Next
end if
next
ListServices(strComputer)
End Sub
Sub btn_Refresh_onClick()
ListServices(strComputer)
End Sub
Sub btn_Connect_onClick()
strComputer = InputBox("Enter a computer","Computer Name","computer-name-here")
if strComputer = "" then
strComputer = "."
end if
span_computername.InnerHTML = uCase(strcomputer)
ListServices(strComputer)
End Sub
Sub btn_exit_onClick()
Window.Close
End Sub
function list_servicenames_ColumnClick(colheader)
list_servicenames.SortKey = colheader.index-1
end function
</script>
<body>
You are connected to: <span id="span_computername"> </span><br>
<input type="button" value="Connect to computer..." name="btn_Connect" id="btn_Connect" title="Click to enter a computer name to connect to"><br><br>
<OBJECT id="list_servicenames" name="list_servicenames" classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628"></OBJECT>
<br />
<input type="button" value="Refresh" name="btn_Refresh" id="btn_Refresh" title="Click to refresh the services list">
<input type="button" value="Start" name="btn_start" id="btn_start" title="Click to Start the Services">
<input type="button" value="Stop" name="btn_stop" id="btn_stop" title="Click to Stop the Service">
<input type="button" value="Restart" name="btn_restart" id="btn_restart" title="Click to Restart the Services">
<input type="button" value="Exit" name="btn_exit" id="btn_exit" title="Click to Exit Form ">
</body>
I appoligize that I don't have the time today to convert your example into a working example.
Open in new window