程序终结者的VBS代码

时间:2013-07-14 07:43:36

标签: vbscript process terminator

我想要一个VBS代码:

显示输入框以输入进程名称

并且可以将该过程附加到下面编写的代码中:

Option Explicit
Dim strComputer, strProcessToKill, objWMIService, colProcess, objProcess

strComputer = "."
strProcessToKill = "notepad.exe"
Set objWMIService = GetObject("winmgmts:" _ 
  & "{impersonationLevel=impersonate}!\\" _ 
  & strComputer _ 
  & "\root\cimv2") 
Set colProcess = objWMIService.ExecQuery _
  ("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")
For Each objProcess in colProcess
  msgbox "... terminating " & objProcess.Name
  objProcess.Terminate()
Next

1 个答案:

答案 0 :(得分:2)

替换

strProcessToKill = "notepad.exe"

strProcessToKill = InputBox("Enter process name:")

您应该添加一些安全检查,以防用户按下Cancel或按OK而没有输入任何内容:

If IsEmpty(strProcessToKill) Then
  WScript.Echo "User pressed 'Cancel'."
  WScript.Quit 1
ElseIf strProcessToKill = "" Then
  WScript.Echo "Nothing entered."
  WScript.Quit 1
End If