문제

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