Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vbs taskkill by name

I'am trying to find how to close a process using it's title.

I found the command:

taskkill /fi "WINDOWTITLE eq the_title_of_the_windows"

and it works great.

When I try:

oShell.Run "taskkill /fi "WINDOWTITLE eq the_title_of_the_windows"", , True

I get an error and it won't compile.

Any idea on how to use th symbole " in this line?

like image 691
Joe Lara Avatar asked Jan 24 '26 17:01

Joe Lara


2 Answers

In order to use double quotation marks inside another pair of double quotation marks, you need to use "" instead of just ", because if you use one quotation mark " it will be considered the end of text between the first and the second quotation marks

So, your code should look like this:

oShell.Run "taskkill /fi ""WINDOWTITLE eq the_title_of_the_windows""", , True

The following example will terminate all processes with window title (Calculator):

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.Run "taskkill /fi ""WINDOWTITLE eq Calculator""", , True

Hope that helps :)

like image 80
41686d6564 stands w. Palestine Avatar answered Jan 26 '26 06:01

41686d6564 stands w. Palestine


Alternatively you can try below code: This code will pick the task from Task manager and close the process. Copy pasted the code in ".vbs" File and use call KillAll("your task name.exe")

Function KillAll(ProcessName)
    Dim objWMIService, colProcess
    Dim strComputer, strList, p
    Dim i :i= 0 
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
    Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process Where Name like '" & ProcessName & "'")
    For Each p in colProcess
        p.Terminate     
    i = i+1        
    Next
    MsgBox("Total Instance :: " &i& " of "&ProcessName&" is killed")
End Function

call KillAll("MicrosoftEdge.exe")
like image 43
Prabhat Kumar Avatar answered Jan 26 '26 07:01

Prabhat Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!