Search code examples
vbscripttaskkill

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?


Solution

  • 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 :)