您的位置:首页 > 编程语言 > VB

vbs+hta 实现同时关闭多个系统进程

2007-09-04 09:50 267 查看
本代码通过 xp mshta.exe 解析执行
-----------------------------------------------------------------------------------
<HEAD>
<title>进程中断</title>
<HTA:APPLICATION
APPLICATIONNAME="进程中断"
BORDER="THICK"
caption="进程中断"
maximizebotton="yes"
minmizebutton="yes"
scroll="yes"
showintaskbar="yes"
singleinstance="yes"
sysmenu="yes"
windowstate="maximize"
>
</HEAD>
<SCRIPT LANGUAGE="VBScript">

Set os0=createobject("shell.application")
Set wmi=GetObject("winmgmts://.")
Set d0=CreateObject("scripting.dictionary")

Sub list
d0.RemoveAll
n=1
dataarea.innerhtml=Nothing
strHTML = strhtml&"<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
strhtml = strhtml&"<tr>"& _
"<td width='3%'>"&"<font size=2>"&"序号"&"</font>"&"</td>"& _
"<td width='20%'>"&"<font size=2>"&"名称"&"</font>"&"</td>"& _
"<td width='7%'>"&"<font size=2>"&"PID"&"</font>"&"</td>"& _
"<td width='70%'>"&"<font size=2>"&"命令行"&"</font>"&"</td>"
Set pro_s=wmi.instancesof("win32_process")
For Each p In pro_s
strhtml = strhtml&"<tr>"& "<td width='3%'>"& _
"<font size=2>"&n&"</font>"&"</td>"&"<td width='20%'>"& _
"<font size=2>"&p.name&"</font>"&"</td>"& "<td width='7%'>"& _
"<font size=2>"&p.handle&"</font>"&"</td>"& "<td width='70%'>"& _
"<font size=2>"&p.commandline&"</font>" _
&"</td>"

d0.Add ""&n,Trim(p.handle)
n=n+1
Next
dataarea.innerhtml=strhtml
End Sub

Sub stop_p
xs=Split(txt.value,",",-1,1)
for i=0 to ubound(xs)
for n=0 to ubound(xs)
if n=i then
n=n+1
if n>ubound(xs) then exit for
end if
if xs(n)=xs(i) or _
Trim(xs(n))="" Then
xs(n)="-1"
end If
next
Next
w=0
For i=0 To UBound(xs)
If d0.Exists(xs(i))=False Then
xs(i)="-2"
w=w+1
End If
Next
w=(UBound(xs)+1-w)
If w=0 Then
MsgBox "需要中断的进程序号列表无效,"&Chr(13)& _
"可能需要关闭的进程不存在或者输入的序号格式不正确,请打开进程列表确认!"
Else
strhtml="<font size=2>"&"已被中断的进程"&"</font>"&"<br>"
strHTML = strhtml&"<table border='1' style='border-collapse: collapse' " & _
"bordercolor='#111111' width='100%' id='Table1' >"
For i=0 To UBound(xs)
If xs(i) <> "-2" Then
Set pro_s=wmi.EXECQUERY("Select * FROM WIN32_PROCESS Where HANDLE='"&D0(XS(I))&"'" )
N=1
For Each p In pro_s
pd=p.terminate()
If pd=0 Then
strhtml = strhtml&"<tr>"& "<td width='3%'>"&"<font size=2>"&xs(i)&"</font>"&"</td>"& _
"<td width='20%'>"&"<font size=2>"&p.name&"</font>"&"</td>"& _
"<td width='7%'>"&"<font size=2>"&p.handle&"</font>"&"</td>"& _
"<td width='70%'>"&"<font size=2>"&p.commandline&"</font>"&"</td>"
D0.Remove(xs(i))
n=n+1
End If
Next
If N=0 Then '要关闭的进程可能被牵连关闭了
strhtml = strhtml&"<tr>"& "<td width='3%'>"& _
"<font size=2>"&xs(i)&"</font>"&"</td>"&"<td width='20%'>"& _
"<font size=2>"&p.name&"</font>"&"</td>"& "<td width='7%'>"& _
"<font size=2>"&p.handle&"</font>"&"</td>"& "<td width='70%'>"& _
"<font size=2>"&p.commandline&" 已经被间接关闭"&"</font>"& _
"</td>"
D0.Remove(xs(i))
End if
End If
Next
dataarea.innerhtml=dataarea.innerhtml&strhtml
txt.value=""
End If
End Sub

</SCRIPT>

<body>
<input type="button" value="进程列表" name="list_button" onClick="list"><p>
<span id="dataarea"></span><br>
输入欲中断的进程序号,如:1,2,5,7,55...
<input type="text" name="txt" size=60 value="">
<input type="button" value="中断进程" name="stop_p_button" onClick="stop_p">
<p>
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: