nicochulo
nicochulo

Reputation: 111

How to close task manager with VBScript

I am trying to close task manager using the following taskkill command:

taskkill /f /im Taskmgr.exe

But it tells me that I can't because there is an error, I lack access.

Is there any way to acquire those permissions with a more complex taskkill or something along those lines?

If that's not possible,here's the code I'm using,there might be a way to substitute the taskkill for an Alt + F4 or another method,all ideas are welcome

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

Upvotes: 1

Views: 1439

Answers (4)

bee dealer
bee dealer

Reputation: 1

try this:

Dim oShell : Set oShell = CreateObject("WScript.Shell")
oShell.Run "taskkill /im Taskmgr.exe", , True

this works on my non admin account so maybe it will work with your purposes

Upvotes: 0

hollopost
hollopost

Reputation: 597

Dim wshShell : Set wshShell = WScript.CreateObject ("WScript.Shell")
wshShell.Exec "taskkill /fi ""WINDOWTITLE eq Task Manager"""

Upvotes: 1

Hackoo
Hackoo

Reputation: 18857

This vbscript can did the trick :

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
'*********************************************************************************************

Upvotes: 3

Kamil Kowalewski
Kamil Kowalewski

Reputation: 31

I have no excel by myself to try it out, but maybe a:

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

would work

Upvotes: 3

Related Questions