0

我想要一个 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
4

1 回答 1

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
于 2013-07-14T08:39:59.193 回答