首页 > 编程 > VBScript > 正文

杀死指定进程名称的小VBS

2020-06-26 17:38:55
字体:
来源:转载
供稿:网友

以下是一小段杀死指定进程名字的小vbs,希望对大家有帮助。

Function KillProc(strProcName)On Error Resume Next Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!//./root/cimv2") Set arrProcesses = objWMIService.ExecQuery( "select * from win32_process where Name ='"&strProcName&"'" ) For Each proccess In arrProcesses proccess.Terminate 0  NextEnd Function

VBS命令-进程操作代码(检测进程, 结束进程)

//检测进程进程名 = "qq.exe"返回值 = IsProcess(进程名)If 返回值 = True ThenMessageBox "发现进程"ElseIf 返回值 = False ThenMessageBox "没有发现进程"End If//检测进程 优化后的代码If IsProcess("qq.exe") = True Then MessageBox "发现进程"Else MessageBox "没有发现进程"End If//检测进程组进程组 = "qq.exe|notepad.exe"返回值 = IsProcessEx(进程组)If 返回值 = True ThenMessageBox "发现进程"ElseIf 返回值 = False ThenMessageBox "没有发现进程"End If//检测进程组 优化后的代码If IsProcessEx("qq.exe|notepad.exe") = True Then MessageBox "发现进程"Else MessageBox "没有发现进程"End If//结束进程 前台执行进程名 = "qq.exe"Call CloseProcess(进程名, 1)//结束进程 后台执行进程名 = "qq.exe"Call CloseProcess(进程名, 0)//结束进程组 前台执行进程组 = "qq.exe|notepad.exe"Call CloseProcessEx(进程组, 1)//结束进程组 后台执行进程组 = "qq.exe|notepad.exe"Call CloseProcessEx(进程组, 0)//实例应用 结束进程 前台执行 10秒超时进程名 = "qq.exe"For 10Call CloseProcess(进程名,1)Delay 1000返回值 = IsProcess(进程名)If 返回值 = False ThenExit ForEnd IfNextIf 返回值=True ThenMessageBox "结束进程失败"ElseMessageBox "结束进程成功"End If//实例应用 结束进程 前台执行 优化后的代码(直到型循环) 有些进程VBS检测不到 所以先关闭后检测DoCall CloseProcess("qq.exe",1)Delay 1000Loop While IsProcess("qq.exe")=TrueMessageBox "结束进程成功"//实例应用 结束进程组 后台执行 10秒超时进程组 = "qq.exe|notepad.exe"For 10Call CloseProcessEx(进程组,0)Delay 1000返回值 = IsProcessEx(进程组)If 返回值 = False ThenExit ForEnd IfNextIf 返回值=True ThenMessageBox "结束进程失败"ElseMessageBox "结束进程成功"End If//实例应用 结束进程组 后台执行 优化后的代码(直到型循环) 有些进程VBS检测不到 所以先关闭后检测DoCall CloseProcessEx( "qq.exe|notepad.exe",0)Delay 1000Loop While IsProcessEx( "qq.exe|notepad.exe")=TrueMessageBox "结束进程成功"//函数 子程序部分代码//检测进程Function IsProcess(ExeName)Dim WMI, Obj, Objs,iIsProcess = FalseSet WMI = GetObject("WinMgmts:")Set Objs = WMI.InstancesOf("Win32_Process")For Each Obj In ObjsIf InStr(UCase(ExeName),UCase(Obj.Description)) <> 0 ThenIsProcess = TrueExit ForEnd IfNextSet Objs = NothingSet WMI = NothingEnd Function//结束进程Sub CloseProcess(ExeName,RunMode)dim wsSet ws = createobject("Wscript.Shell")ws.run "cmd.exe /C Taskkill /f /im " & ExeName,RunModeSet ws = NothingEnd Sub//检测进程组Function IsProcessEx(ExeName)Dim WMI, Obj, Objs,ProcessName,iIsProcessEx = FalseSet WMI = GetObject("WinMgmts:")Set Objs = WMI.InstancesOf("Win32_Process")ProcessName=Split(ExeName,"|")For Each Obj In ObjsFor i=0 to UBound(ProcessName)If InStr(UCase(ProcessName(i)),UCase(Obj.Description)) <> 0 ThenIsProcessEx = TrueExit ForEnd IfNextNextSet Objs = NothingSet WMI = NothingEnd Function//结束进程组Sub CloseProcessEx(ExeName,RunMode)dim ws,ProcessName,CmdCode,iProcessName = Split(ExeName, "|")For i=0 to UBound(ProcessName)CmdCode=CmdCode & " /im " & ProcessName(i)NextSet ws = createobject("Wscript.Shell")ws.run "cmd.exe /C Taskkill /f" & CmdCode,RunModeSet ws = NothingEnd Sub


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表