VBS批量关闭进程

每次下班的时候,都要关闭一大堆软件,虽然说也就两三分钟的事儿,但能用代码思想去搞定这两三分钟也是极好的。

在参考了网上一些方法后汇总了一下,将其保存为.vbs文件,修改里面的参数,然后下班的时候点一下就OK了。

'提升为管理员权限,否则无法干掉SYSTEM进程
Set WshShell = WScript.CreateObject("WScript.Shell") 
If WScript.Arguments.Length = 0 Then
  Set ObjShell = CreateObject("Shell.Application") 
  ObjShell.ShellExecute "wscript.exe" _ 
  , """" & WScript.ScriptFullName & """ RunAsAdministrator", , "runas", 1 
  WScript.Quit 
End if

'添加需要批量关闭的进程名
Dim PsName
PsName="Closed "
Dim Dic : Set Dic = CreateObject("Scripting.Dictionary")
Dic.Add "QQ", "QQ.exe"
Dic.Add "WeChat", "WeChat.exe"
Dic.Add "ToDesk", "ToDesk.exe"
Dic.Add "ToDeskServer", "ToDesk_Service.exe"

'关闭进程方法
sub Close_Process(ProcessName) 
'On Error Resume Next:出现错误继续执行
'On Error Goto 0:出现错误中断并弹出错误
On Error Resume Next 
    for each process in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_ 
        if Ucase(process.name)=Ucase(ProcessName) then 
            process.terminate 
        end if 
    next 
end sub 

'循环关闭进程
For i = 0 To Dic.Count - 1
    Dim DictKeys, DictItems
    DicKeys = Dic.Keys
    DicItems = Dic.Items
    PsName=PsName+" "+DicKeys(i)
    Close_Process(DicItems(i))
Next

msgbox PsName

 

posted @ 2021-01-27 14:32  TenFly  阅读(742)  评论(0编辑  收藏  举报