I would like a VBS code that:

Displays an input box to enter a process name

and can append the process to the code written below:

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
有帮助吗?

解决方案

Replace the line

strProcessToKill = "notepad.exe"

with

strProcessToKill = InputBox("Enter process name:")

You should add some safety checks, though, in case the user presses Cancel or presses OK without having anything entered:

If IsEmpty(strProcessToKill) Then
  WScript.Echo "User pressed 'Cancel'."
  WScript.Quit 1
ElseIf strProcessToKill = "" Then
  WScript.Echo "Nothing entered."
  WScript.Quit 1
End If
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top