我正在尝试使用以下taskkill命令关闭任务管理器:
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 :(得分:3)
我自己没有尝试过尝试,但也许是:
If objProcess.name = "Taskmgr.exe" then
objProcess.Terminate()
End if
会起作用
答案 1 :(得分:3)
这个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
'*********************************************************************************************
答案 2 :(得分:2)
Dim wshShell : Set wshShell = WScript.CreateObject ("WScript.Shell")
wshShell.Exec "taskkill /fi ""WINDOWTITLE eq Task Manager"""
答案 3 :(得分:0)
试试这个:
Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.Run "taskkill /im Taskmgr.exe", , True
这适用于我的非管理员帐户,所以也许它可以满足您的目的