Jump to content

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

Getting path of active program


  • Please log in to reply
3 replies to this topic
vbmark
  • Members
  • 57 posts
  • Last active: Dec 10 2018 06:35 PM
  • Joined: 11 Nov 2005
I am trying to get the path of the active program by using a script I found...

GetPath()
{
	WinGet, pid, PID
	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)
	MsgBox %Proc%
	Return
}

It returns Chinese characters. Why would that be?
Best freeware:
http://www.vbmark.com

vbmark
  • Members
  • 57 posts
  • Last active: Dec 10 2018 06:35 PM
  • Joined: 11 Nov 2005
I found a more advance/updated version here:
http://www.autohotke...t=4182&start=15

But I still get this back:
Posted Image

I get that back just from simple Notepad too.

Any thoughts?
Best freeware:
http://www.vbmark.com

nimda
  • Members
  • 4368 posts
  • Last active: Aug 09 2015 02:36 AM
  • Joined: 26 Dec 2010
You're using Unicode, while the function call is ANSI. Here's how it should be done:
GetPath()
{
   WinGet, pid, PID, A ; for testing on the active window
   h_process := DllCall("OpenProcess", UInt,0x418, Int,0, UInt,pid)
   VarSetCapacity(Proc, 255)
   DllCall("psapi.dll\GetModuleFileNameEx" [color=red](A_IsUnicode ? "W" : "A")[/color], UInt,h_process, UInt,0, Str,Proc, UInt,255)
   DllCall("CloseHandle", [color=red]UInt,[/color] h_process)
   MsgBox % proc
   Return
}
GetPath()


vbmark
  • Members
  • 57 posts
  • Last active: Dec 10 2018 06:35 PM
  • Joined: 11 Nov 2005
Thank you so very much nimda!

I was beginning to give up hope on this one.

I appreciate your time.

Thank you.
Best freeware:
http://www.vbmark.com