mcu
mcu

Reputation: 3522

Check if a program is running by executable path

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.

Upvotes: 5

Views: 18273

Answers (2)

manojlds
manojlds

Reputation: 301607

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
}

Upvotes: 14

Andrew Shepherd
Andrew Shepherd

Reputation: 45272

$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

Upvotes: 2

Related Questions