Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get path of exe

1,029 views
Skip to first unread message

Sandy

unread,
Feb 18, 2005, 9:17:10 AM2/18/05
to
Is there a way to get the path of a running executable, through Windows API
call?
Thanks for your help,

Sandy
---== Posted via the PFCGuide Web Newsreader ==---
http://www.pfcguide.com/_newsgroups/group_list.asp

kishore

unread,
Feb 18, 2005, 9:26:31 AM2/18/05
to
[PB external function declaration]
FUNCTION int GetModuleFileNameA(&
ulong hinstModule, &
REF string lpszPath, &
ulong cchPath) LIBRARY "kernel32"

[Powerscript]
string ls_Path
unsignedlong lul_handle

ls_Path = space(1024)

lul_handle = Handle(GetApplication())
GetModuleFilenameA(lul_handle, ls_Path, 1024)
MessageBox("Current application path", ls_path)

KISHORE

"Sandy" <NOCANSPAM...@hanys.org> wrote in message
news:4215f8e6$1@forums-1-dub...

Sandy

unread,
Feb 18, 2005, 9:56:21 AM2/18/05
to
Thank you for you suggestion.
I just tried your code, but it didn't work. If I run my executable from a DOS
prompt at C:\ (to simulate running from somewhere other than the directory where
the program resides)giving the path to the exe, the messagebox returns C:\, not
my full path to the app.

Sandy

On 18 Feb 2005 06:26:31 -0800,
in sybase.public.powerbuilder.general

kishore

unread,
Feb 18, 2005, 10:07:34 AM2/18/05
to
Hi,

I tried it in my exe, it is working it give full path.

Just send me your exe path.

Kishore


"Sandy" <NOCANSPAM...@hanys.org> wrote in message

news:42160215$1@forums-1-dub...

Sandy

unread,
Feb 18, 2005, 10:11:29 AM2/18/05
to
My exe path is C:\uds_pb8_apps\udsdev\uds.exe

Thanks for your help,
Sandy

On 18 Feb 2005 07:07:34 -0800,

Sandy

unread,
Feb 18, 2005, 10:14:53 AM2/18/05
to
I am getting an error on the call to GetModuleFilenameA. Any ideas why?
Sandy

On 18 Feb 2005 07:11:29 -0800,
in sybase.public.powerbuilder.general

Terry Voth [TeamSybase]

unread,
Feb 18, 2005, 11:10:13 AM2/18/05
to
If you're using PB10, you either need to use GetModuleFilenameW, or use the
";ANSI" qualifier on the external function declaration.

Good luck,

Terry [TeamSybase] and Sequel the techno-kitten

On 18 Feb 2005 07:14:53 -0800,

*********************************
Click once a day to help the hungry
http://www.thehungersite.com
*********************************

Sequel's Sandbox: http://www.techno-kitten.com
Home of PBL Peeper, a free PowerBuilder Developer's Toolkit.
Version 2.2.06 now available at the Sandbox
See the PB Troubleshooting Guide at the Sandbox
^ ^
o o
=*=

Jason 'Bug' Fenter

unread,
Feb 18, 2005, 11:21:01 AM2/18/05
to
I'm using the exact same code that Kishore has with the exception that the
external function returns a ULong and instead of 1024, I'm using 255. The
code has worked reliably for me on Win2K and WinXP. (I *think* I've used it
on Win95, but that was so long ago that I can't remember.) Also remember
that when you run through the PB IDE, Handle (GetApplication ()) returns
0... not a valid handle. My application is "fact.exe" and it uses "fact.ini"
in the same directory. Here's my code...

String ls_Path
ULong ll_Handle, &
ll_Length

// Grab the INI file.
ll_Handle = Handle (GetApplication ())
IF ll_Handle = 0 THEN
is_INI = "C:\Documents and Settings\Jason\My Documents\PB\FACT\FACT.ini"
ELSE
ll_Length = 255
ls_Path = Space (ll_Length)

GetModuleFileName (ll_Handle, ls_Path, ll_Length)
is_INI = Left (ls_Path, Len (ls_Path) - 3) + "ini"
END IF


... and my external function is defined as
FUNCTION ULong GetModuleFileName (ULong hinstModule, REF String lpszPath,
ULong cchPath) LIBRARY "kernel32.dll" ALIAS FOR "GetModuleFileNameA"

"Sandy" <NOCANSPAM...@hanys.org> wrote in message

news:4216066d$1@forums-1-dub...

0 new messages