2017-09-02 154 views
0

我嘗試使用下面的taskkill命令來關閉任務管理器:如何關閉任務管理器使用VBScript

taskkill /f /im Taskmgr.exe 

但它告訴我,我不能因爲有一個錯誤,我無法獲得。

有沒有什麼辦法可以通過更復雜的taskkill獲得這些權限?

如果這是不可能的,這裏是我使用的代碼,有可能是替代的taskkill按下ALT + F4或其它方法的方式,所有的想法,歡迎

Set WshShell = WScript.CreateObject ("WScript.Shell") 
Set objShell = CreateObject("Wscript.Shell") 
do 
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process") 

For Each objProcess in colProcessList 
If objProcess.name = "Taskmgr.exe" then 
vFound = True 
End if 
Next 

If vFound = True then 
objShell.Run "taskkill /f /im Taskmgr.exe", , True 
vFound = False 
End If 
loop 
+0

什麼可能的有效原因是程序化地終止任務管理器進程? – Lankymart

+0

如果我很誠實,我只想惹人。我的意思是,我不會摧毀一臺電腦或任何東西,但我想在朋友的電腦上安裝一段時間。我沒有別的 – nicochulo

+0

幾乎我所期望的。 – Lankymart

回答

0

這VBScript中可以做的伎倆:

Option Explicit 
If AppPrevInstance() Then 
    MsgBox "There is an existing proceeding !" & VbCrLF &_ 
    CommandLineLike(WScript.ScriptName),VbExclamation,"There is an existing proceeding !"  
    WScript.Quit 
Else 
Do 
    Call KillProcess("TaSkMgR.ExE") 
Loop 
End If 
'************************************************************************************* 
Sub KillProcess(MyProcess) 
Dim colProcessList,objProcess 
Set colProcessList = GetObject("Winmgmts:").ExecQuery ("Select * from Win32_Process") 
For Each objProcess in colProcessList 
    If LCase(objProcess.name) = LCase(MyProcess) then 
     objProcess.Terminate() 
    End if 
Next 
End Sub 
'********************************************************************************************* 
Function AppPrevInstance() 
    With GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2") 
     With .ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE " & CommandLineLike(WScript.ScriptFullName) & _ 
      " AND CommandLine LIKE '%WScript%' OR CommandLine LIKE '%cscript%'") 
      AppPrevInstance = (.Count > 1) 
     End With 
    End With 
End Function  
'********************************************************************************************* 
Function CommandLineLike(ProcessPath) 
    ProcessPath = Replace(ProcessPath, "\", "\\") 
    CommandLineLike = "'%" & ProcessPath & "%'" 
End Function 
'********************************************************************************************* 
+0

謝謝!這段代碼工作得非常好! – nicochulo

1

我沒有Excel中由我自己嘗試一下,但也許一:

If objProcess.name = "Taskmgr.exe" then 
    objProcess.Terminate() 
End if 

會工作

+0

嗯....我測試了一下更多....它在最初的幾次工作,但由於某種原因,它停止工作後,第三次左右......我不知道爲什麼 – nicochulo

+0

終止方法應返回整數,這是發生錯誤的代碼數。也許這會幫助 –

+0

我很抱歉,但我不擅長編碼。我可以通過修改來解決問題嗎? – nicochulo

相關問題