程序試驗環境為 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
'--------如果用戶取消了操作,就退出程序 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
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 "需要中斷的進程列表為空!" WScript.Quit End If
'-------------根據用戶輸入信息中斷相應進程 m=0 For i=0 To UBound(xs) If xs(i) "-2" then '---只有真實可用的序號才參與循環 For Each p In pro_s If Trim(p.handle)=trim(d0(xs(i))) Then '---如果進程pid號碼正是需要中斷的就嘗試中斷 p_name=p.name pd=p.terminate() If pd=0 Then '---判斷中斷進程的嘗試是否成功 msg=p_name&" 進程中斷成功!" m=m+1 Else msg=p_name&" 進程中斷失敗!" End If os.popup msg,1,"通知",64+0 End If Next end if Next