我获得了一个HTA,我认为是由HTA_Helpomatic创建的。他们希望将其转换为经典的ASP页面。所以我做了一些基本的改动,我想我几乎有它的工作。但我遇到了一个问题 - “需要VBScript对象”这一点。它在行上设置objlst_groupnames = document.getElementById(“list_servicenames”) 这是最初的HTA脚本 - 任何人都可以帮我弄清楚如何正确地将其转换为ASP?我创建了一个类似的页面,但它没有按照他们想要的方式工作(你必须点击每个服务来切换它,而不是点击一个复选框)。感谢。
<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>
答案 0 :(得分:0)
要获取客户端点击事件以激活服务器上的某些内容,您必须使用类似AJAX的内容。