Results 1 to 6 of 6

Thread: API always return same result... GetModuleHandle & GetModuleFileName

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    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

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    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........

  3. #3
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: API always return same result... GetModuleHandle & GetModuleFileName

    I am trying to get program location.

  5. #5
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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
  •  



Click Here to Expand Forum to Full Width