I was given an HTA that I think was created by the HTA_Helpomatic. They want it converted into a classic ASP page. So I made a few basic changes, and I think I almost have it working. But I'm running into a problem - the ole 'VBScript Object Required' bit. It's doing this on the line Set objlst_groupnames = document.getElementById( "list_servicenames" ) Here's the original HTA script - can anyone help me figure out how to properly convert this to ASP? I had a similar page created, but it didn't work the way they wanted (You had to click on each service to toggle it, vs just clicking on a check box). Thanks.
<head>
<title>Start/Stop/Restart Windows Services</title>
<HTA:APPLICATION
APPLICATIONNAME="Start/Stop/Restart Windows Services"
BORDER="thin"
SCROLL="yes"
SINGLEINSTANCE="yes"
ID="oHTA"
>
<APPLICATION:HTA>
</head>
<script language="VBScript">
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
sComputer = MachineName.Value
ListServices(sComputer)
End Sub
Sub ListServices(sComputer)
ON ERROR RESUME NEXT
sServiceName = ServiceName.Value
Set objList = document.getElementById( "list_servicenames" )
objList.ListItems.Clear
set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sComputer & "\root\cimv2")
if sServiceName = "" then
Set colItems = objWMIService.ExecQuery("Select * from Win32_Service")
else
Set colItems = objWMIService.ExecQuery("Select * From Win32_Service where DisplayName like '%" & sServiceName & "%'")
end if
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()
sComputer = MachineName.Value
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}!\\" & sComputer & "\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(sComputer)
End Sub
Sub btn_stop_onClick()
sComputer = MachineName.Value
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}!\\" & sComputer & "\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(sComputer)
End Sub
Sub btn_restart_onClick()
sComputer = MachineName.Value
'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}!\\" & sComputer & "\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}!\\" & sComputer & "\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(sComputer)
End Sub
Sub btn_Refresh_onClick()
sComputer = MachineName.Value
ListServices(sComputer)
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>
Enter Machine Name: <Input Type = "Text" Name = "MachineName">
<Input Type = "Button" Value = "Get Services" Name = "Run_Button" onClick = "Window_OnLoad"> Filter Services by Name: <Input Type = "Text" Name = "ServiceName"><P>
<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 ">
<br/>
<OBJECT id="list_servicenames" name="list_servicenames" classid="clsid:BDD1F04B-858B-11D1-B16A-00C0F0283628"></OBJECT>
</body>