用vbs實現(xiàn)的瞬間關閉多個系統(tǒng)進程的腳本
更新時間:2008年06月20日 19:24:50 作者:
程序利用 vbs 的wmi 、scripting.filesystemobject、shell.application、scripting.dictionary、wscript.shell的相關功能功能實現(xiàn)將當前進程列表顯示在一個文本文件中,通過用戶界面的選擇,確定需要瞬間中斷的進程列表,然后中斷之。
程序試驗環(huán)境為 windows xp_sp2,主要針對系統(tǒng)存在多個需要中斷進程的情況下,瞬間成批中斷進程。
'----------------------------------------------------------------------------------
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")
'-------------創(chuàng)建臨時文本文件文件,把當前進程輸入該文本文件之中并通過記事本打開之
'---------同時把進程對應序號 和 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("請根據(jù)"&filename&"中的內(nèi)容"+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
'--------把用戶輸入的序號列中相關的序號傳遞給一個數(shù)組 xs
xs=Split(x,",",-1,1)
'-----------對用戶輸入的序號列進行校對,將重復序號標記為 -2,計算實際序號個數(shù)
For i=0 to ubound(xs) '---利用雙重循環(huán)將重復輸入的內(nèi)容保留一份,其他的標記為-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 '----把不真實可用的序號剔除并計算出其個數(shù)
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) '---得出可用的序號個數(shù)
'------------如果序列中沒有輸入任何序號就退出程序
If w=0 Then
MsgBox "需要中斷的進程列表為空!"
WScript.Quit
End If
'-------------根據(jù)用戶輸入信息中斷相應進程
m=0
For i=0 To UBound(xs)
If xs(i) <> "-2" then '---只有真實可用的序號才參與循環(huán)
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
os.popup w&"個目標進程,已經(jīng)中斷了"&m&"個" ,5,"通知",64+0
WScript.quit
復制代碼 代碼如下:
'----------------------------------------------------------------------------------
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")
'-------------創(chuàng)建臨時文本文件文件,把當前進程輸入該文本文件之中并通過記事本打開之
'---------同時把進程對應序號 和 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("請根據(jù)"&filename&"中的內(nèi)容"+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
'--------把用戶輸入的序號列中相關的序號傳遞給一個數(shù)組 xs
xs=Split(x,",",-1,1)
'-----------對用戶輸入的序號列進行校對,將重復序號標記為 -2,計算實際序號個數(shù)
For i=0 to ubound(xs) '---利用雙重循環(huán)將重復輸入的內(nèi)容保留一份,其他的標記為-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 '----把不真實可用的序號剔除并計算出其個數(shù)
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) '---得出可用的序號個數(shù)
'------------如果序列中沒有輸入任何序號就退出程序
If w=0 Then
MsgBox "需要中斷的進程列表為空!"
WScript.Quit
End If
'-------------根據(jù)用戶輸入信息中斷相應進程
m=0
For i=0 To UBound(xs)
If xs(i) <> "-2" then '---只有真實可用的序號才參與循環(huán)
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
os.popup w&"個目標進程,已經(jīng)中斷了"&m&"個" ,5,"通知",64+0
WScript.quit
相關文章
使用 iisweb.vbs 刪除網(wǎng)站的方法(支持批量刪除)
有時候我們需要批量刪除網(wǎng)站,如果一個一個手工刪除肯定太慢了,這里分享個命令,通過iisweb.vbs批量刪除網(wǎng)站2014-07-07
vbs解決處理TXT文本數(shù)據(jù)相關問題實現(xiàn)代碼
使用vbs處理txt數(shù)據(jù)時,會遇到一些問題,本文將提供詳細的解決方法,希望可以幫助你們2012-12-12
VBS獲取GZIP壓縮的HTTP內(nèi)容的實現(xiàn)代碼
這篇文章主要介紹了VBS獲取GZIP壓縮的HTTP內(nèi)容的實現(xiàn)代碼,需要的朋友可以參考下2016-01-01
VBS調(diào)用Photoshop批量生成縮略圖的代碼
這篇文章主要為大家分享了通過vbs調(diào)用Photoshop批量生成縮略圖,需要的朋友可以參考下2013-12-12

