-
May 24th, 2014, 07:28 PM
#1
API always return same result... GetModuleHandle & GetModuleFileName
I first tried with Get_ProgramLocation("VB6.EXE)
Then tried Get_ProgramLocation("Notepad.exe").
My results were always the vb6.exe location...
This is the code I am using.
Code:
Private Const MAX_PATH = 206
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Public Function Get_ProgramLocation(ProgramName As String) As String
Dim lHandle As Long
Dim lRet As Long
Dim sPath As String
sPath = Space$(MAX_PATH)
lHandle = GetModuleHandle(ProgramName)
Debug.Print ProgramName
lRet = GetModuleFileName(lHandle, sPath, MAX_PATH)
Get_ProgramLocation = sPath
End Function
-
May 24th, 2014, 09:36 PM
#2
Re: API always return same result... GetModuleHandle & GetModuleFileName
I believe, Max, that that particular API is designed TO locate the Executable of the "running" program (like C++, VB, etc), not to take a parameter for an EXTERNAL application. I could be wrong........
-
May 24th, 2014, 09:40 PM
#3
Re: API always return same result... GetModuleHandle & GetModuleFileName
What are you trying to achieve?
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 24th, 2014, 09:42 PM
#4
Re: API always return same result... GetModuleHandle & GetModuleFileName
I am trying to get program location.
-
May 24th, 2014, 10:42 PM
#5
Re: API always return same result... GetModuleHandle & GetModuleFileName
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
May 24th, 2014, 10:45 PM
#6
Re: API always return same result... GetModuleHandle & GetModuleFileName
Get_ProgramLocation("Notepad.exe").
Yeah I would not expect that to work.
Think about it, it is possible that you might have 14 files on your HD with that name [unlikely but possible]
You could get the location of some programs from the registry,
You can probably get the location of a program that is currently running but to get a programs location just based on the name would require a HDD search and may return more than one match.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|