程序试验环境为 windows xp_sp2,主要针对系统存在多个需要中断进程的情况下,瞬间成批中断进程。
'----------------------------------------------------------------------------------
On Error Resume next
Set fs=CreateObject("scripting.filesystemobject")
Set os=CreateObject("wscript.shell")
Set os0=createobject("shell.application")
Set d0=CreateObject("scripting.dictionary")
Set wmi=GetObject("winmgmts:.")
Set pro_s=wmi.instancesof("win32_process")
'-------------创建临时文本文件文件,把当前进程输入该文本文件之中并通过记事本打开之
'---------同时把进程对应序号 和 pid 传递给dictionary(d0)一份
filename=fs.GetTempName
set f1=fs.CreateTextFile(filename,True)
msg="序号"&vbTab&"名称"&vbTab&"PID"&vbTab&"程序文件"&vbtab&now&Chr(10)
f1.Writeline(msg)
n=1
For Each p In pro_s
f1.WriteLine(n&". "&p.name&" , "&p.handle&" , "&p.commandline&Chr(10))
d0.Add ""&n,Trim(p.handle)
n=n+1
Next
f1.Close
os0.MinimizeAll
os.Exec "notepad.exe "&filename
wscript.sleep 500
'--------------等待用户输入欲中断的进程相关的序号列,确定之后关闭并删除临时文本文件
x=InputBox("请根据"&filename&"中的内容"+Chr(10)+ _
"选择需要同时中断的进程对应序号:"+Chr(10)+ _
"(序号之间用','间隔 例如:'1,3,5,7,11')","选择")
os.AppActivate filename&" - 记事本"
os.SendKeys "%fx"
WScript.Sleep 500
fs.DeleteFile filename
'--------如果用户取消了操作,就退出程序
If x="" then wscript.quit
'--------把用户输入的序号列中相关的序号传递给一个数组 xs
xs=Split(x,",",-1,1)
'-----------对用户输入的序号列进行校对,将重复序号标记为 -2,计算实际序号个数
For i=0 to ubound(xs) '---利用双重循环将重复输入的内容保留一份,其他的标记为-1
for n=0 to ubound(xs)
if n=i then
n=n+1
if n>ubound(xs) then exit for
end if
if Trim(xs(n))=Trim(xs(i)) Or _
Trim(xs(n))="" Then
xs(n)="-1"
end If
next
Next