vbs 实现瞬间关闭多个系统进程
2008-07-28 09:19
183 查看
程序利用 vbs 的wmi 、scripting.filesystemobject、shell.application、scripting.dictionary、wscript.shell的相关功能功能实现将当前进程列表显示在一个文本文件中,通过用户界面的选择,确定需要瞬间中断的进程列表,然后中断之。程序试验环境为 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
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
os.popup w&"个目标进程,已经中断了"&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")
'-------------创建临时文本文件文件,把当前进程输入该文本文件之中并通过记事本打开之
'---------同时把进程对应序号 和 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
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
os.popup w&"个目标进程,已经中断了"&m&"个" ,5,"通知",64+0
WScript.quit
相关文章推荐
- vbs 实现瞬间关闭多个系统进程
- 用vbs实现的瞬间关闭多个系统进程的脚本
- vbs+hta 实现同时关闭多个系统进程
- java实现关闭windos系统下的进程
- Windows系统使用vbs脚本或bat脚本强制杀死指定所有进程 vbs实现循环持续写入内容到vbs打开开的记事本 使用vbs、bat添加windows计划任务 使用cmd schtasks命令添加windows计划任务
- C#实现关闭其他程序窗口或进程代码分享
- linux下实现文件存储系统,创建和删除大量文件或文件夹时,updatedb进程会更新文件索引节点inode
- 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版
- java开发系统内核:实现进程自动切换,再现Linus当年辉煌一刻
- Win10/Win7小技巧:教你如何彻底关闭系统进程
- 批量定时关闭系统指定进程的小工具
- 安装、进程-云计算学习笔记---hadoop的简介,以及安装,用命令实现对hdfs系统进行文件的上传下载-by小雨
- MFC中实现关闭软件系统
- java开发系统内核:实现进程优先级
- [经验总结]Windows中关闭进程的C++实现
- C#实现WinForm程序的动态系统托图标 关闭主窗体时最小化到系统托盘
- 模拟windows任务管理器列举系统进程,并关闭进程......
- 巧用windows任务管理器中的系统进程关闭无响应程序等电脑疑难问题
- 四种方法实现VC枚举系统当前进程[包含自己注释]
- cmd 查看/关闭系统进程