Finding an application's executable name and path 
Author Message
 Finding an application's executable name and path

I've been trying to get an application's exe name and path.  

I am currently trying to do this using GetModuleFileName.  Here's the
declaration:

Declare Function GetModuleFileName& Lib "kernel32" Alias
"GetModulefileNameA" (ByVal hModule As Long, ByVal lpFileName As String,
ByVal nSize As Long)

I have to pass the hModule in order to get the exe name.  I've tried
getting the module handle using GetModuleHandle, but it's just not working
because that API needs the module name (lpModuleName As String).  Well.  I
have no idea how to get the module name...the only thing I know about the
application are it's hWnd, ProcessID, and Caption.

Any ideas where I am doing something wrong?  Or do you have a better way?

-Sincerely,

Patrick Milam



Tue, 25 Jan 2000 03:00:00 GMT  
 Finding an application's executable name and path

Hi Patrick,

Just use the App object.  Look up App.EXEName and App.Path.
--
{*filter*} Grier
Author of Visual Basic Programmer's Guide to Serial Communications,
ISBN 1-890422-25-8.  Go to http://www.*-*-*.com/ for information.
Contact me at:
Hard & Software
12962 West Louisiana Avenue
Lakewood, CO  80228
303-986-2179 (voice)
303-986-3143 (fax)



Tue, 25 Jan 2000 03:00:00 GMT  
 Finding an application's executable name and path

Quote:

> I've been trying to get an application's exe name and path.

I know my solutions do not use the API, but they are simple.

Get the path with
        App.Path
It's a string.

Why do you not know the EXE name?  Didn't you make the program,
or are you assuming the user will rename the executable file?
Prevent that by checking for the existence of your executable:

If Dir(App.Path & "\filename.exe") = "" Then
        ' Replace filename.exe with your name in above statement
        MsgBox "Don't rename me.", MB_ICONSTOP, "File Renamed"
        <shutdown_program> ' You do this
Endif

Good luck

George



Tue, 25 Jan 2000 03:00:00 GMT  
 Finding an application's executable name and path

According to the winapi c group, GetModuleFileName is not supported under
32-bit windows because it invades another application's memory area.  

--
Randy Birch, MVP Visual Basic

Moderator, Fidonet Visual Basic Programmer's Conference
VBnet, The Visual Basic Developers Resource Centre
http://home.sprynet.com/sprynet/rasanen/



: I've been trying to get an application's exe name and path.  
:
: I am currently trying to do this using GetModuleFileName.  Here's the
: declaration:
:
: Declare Function GetModuleFileName& Lib "kernel32" Alias
: "GetModulefileNameA" (ByVal hModule As Long, ByVal lpFileName As String,
: ByVal nSize As Long)
:
: I have to pass the hModule in order to get the exe name.  I've tried
: getting the module handle using GetModuleHandle, but it's just not
working
: because that API needs the module name (lpModuleName As String).  Well.
I
: have no idea how to get the module name...the only thing I know about the
: application are it's hWnd, ProcessID, and Caption.
:
: Any ideas where I am doing something wrong?  Or do you have a better way?
:
: -Sincerely,
:
: Patrick Milam

:
:
:



Tue, 25 Jan 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Finding Path to VB app's executable

2. Couldn't find net path or user name

3. Long Path Names give Runtime error 76 - Path not found

4. Find the path of an executable.

5. Find'ing an executable

6. Display Dialog to find file name & path

7. Finding .BMP/.ICO path/name in control

8. ADSI:GetObject network path not found reading info other than the current computer name

9. How do I find program name and path ?

10. Getting the path or file name of running application

11. Who do I get the path names of other Application from hWnd

12. Finding Application path of VB .Net project

 

 
Powered by phpBB® Forum Software