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