2013-07-14 26 views
0

我想一個VBS代碼: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 

回答

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 
+0

謝謝...我破解我的頭了吧。 – JSKyeJet