Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Retrieve the path of a running process


  • Please log in to reply
2 replies to this topic
Diamond
  • Members
  • 198 posts
  • Last active: Dec 02 2015 11:18 AM
  • Joined: 31 Mar 2006
Would it be possible to add a parameter to the "Process" command which would return the path of a running process in a variable? I think this would be useful and as far as I know there's no way to do it currently. I discovered this today when I wrote a simple script to show me the process name of the active window and I thought it would be nice if the path could be retrieved as well.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This is a workaround, based on Shimanov's code
#Persistent

CoordMode Mouse, Screen

Settimer Info

Return



Info:

   MouseGetPos X, Y, WinID

   WinGet PID, PID, ahk_id %WinID%

   h_process := DllCall("OpenProcess", UInt,0x418, Int,0, UInt,PID)

   VarSetCapacity(Proc, 255)

   DllCall("psapi.dll\GetModuleFileNameExA", UInt,h_process, UInt,0, Str,Proc, UInt,255)

   DllCall("CloseHandle", h_process)

   ToolTip %Proc%

Return


Diamond
  • Members
  • 198 posts
  • Last active: Dec 02 2015 11:18 AM
  • Joined: 31 Mar 2006
Wow that works great! I don't completely understand how or why it works, but it does. Some DLL calls to get the path? I modified it slightly to get what I was looking for. Thanks a lot. This would still be a useful feature to have built-in to AutoHotkey though for those of us who don't understand complicated things like DLL calls.