Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a process path with VBS

I want to kill a process with vbs, i know the command is :

oShell.Run "taskkill /im software.exe", , True

how to get software.exe path before we kill it ?

Because i want to launch software.exe again.

like image 733
Matt Avatar asked Jun 04 '15 14:06

Matt


1 Answers

WMI (can teminate as well):

dim wmi, list, process, path, shell

set wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 
set list = wmi.ExecQuery("Select * from Win32_Process") 
                  '// or "Select * from Win32_Process where name = 'xxxxxxx.exe'" allowing the removal of the if block

for each process in list
    if (lcase(process.name) = "xxxxxxx.exe") then
        path = process.ExecutablePath
        process.terminate()
        exit for
    end if
next

wscript.echo path

set shell = CreateObject("WScript.Shell")
shell.Run Chr(34) & path & Chr(34)
like image 100
Alex K. Avatar answered Sep 28 '22 01:09

Alex K.