Check if a program is running by executable path

13,349

Solution 1

Try this:

get-process | ?{$_.path -eq $path}

So you can do something like:

if(get-process | ?{$_.path -eq "C:\My Temporary Programs\Test 1.exe"}){
    #exe is running. Do what you want
}

Solution 2

$exePath = 'C:\My Temporary Programs\Test 1.exe'

$isRunning = (get-wmiobject win32_process | ? { 
    $_.Path -eq $exePath
 } | measure-object | % { $_.Count }) -gt 0



# $isRunning is now a boolean value, set to true if there is one or
# more instances running
Share:
13,349

Related videos on Youtube

mcu
Author by

mcu

Updated on June 27, 2022

Comments

  • mcu
    mcu almost 2 years

    In powershell, how do I check if a program is running by using the full path of the program executable? Or do I need to parse the path to get the process name?

    Thanks.

    EDIT:

    I need to know if the executable "C:\My Temporary Programs\Test 1.exe" is running.