Sign in to follow this  
Followers 0
xManh

How to get the path where a process executed from?

6 posts in this topic

Is it possible to get path of a process, for example, getting path of explorer.exe returns C:\Windows\explorer.exe

Thanks for any comment

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Originally pilfered from gafrost, modified slightly by me.

$dir = _GetPIDPath('your.exe')

MsgBox(0, '', $dir)

Func _GetPIDPath($exe)
    $pid = ProcessExists($exe)
    $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2')
    $colItems = $objWMIService.ExecQuery ('SELECT * FROM Win32_Process WHERE ProcessId = ' & $pid, 'WQL', 0x10 + 0x20)
    For $objItem In $colItems
        If $objItem.ExecutablePath Then Return $objItem.ExecutablePath
    Next
EndFunc

edit - because I edit everything at least once.

Edited by xcal

Share this post


Link to post
Share on other sites

Originally pilfered from gafrost, modified slightly by me.

$dir = _GetPIDPath('your.exe')

MsgBox(0, '', $dir)

Func _GetPIDPath($exe)
    $pid = ProcessExists($exe)
    $objWMIService = ObjGet('winmgmts:\\localhost\root\CIMV2')
    $colItems = $objWMIService.ExecQuery ('SELECT * FROM Win32_Process WHERE ProcessId = ' & $pid, 'WQL', 0x10 + 0x20)
    For $objItem In $colItems
        If $objItem.ExecutablePath Then Return $objItem.ExecutablePath
    Next
EndFunc

edit - because I edit everything at least once.

that's cool....

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

Yeah, that's what i'm seeking for, thankyou very much!

Share this post


Link to post
Share on other sites

might want to error check after this line

$pid = ProcessExists($exe)

object errors can crash the program

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Nice advice, thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0