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

本代码通过 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> 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值