Thread: Getting the executable-path from a window

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    76

    Getting the executable-path from a window

    Im trying to get the executable path from a program that is running. I can find the window handle with FindWindow, but now i dont know how to find the path from where the program is running. I saw an example program in msdn which searches all processes, but i dont really like to check all processes when i already got the handle to the window. Does anyone know a way to get the path from the executable from an OTHER program from which i have the handle?

    EDIT. i tried GetWindowModuleFileName but this return the name of my own program.
    Last edited by johny145; 06-02-2005 at 01:02 PM.

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    76
    I found a solution.
    With winnt version you cant use GetWindowModuleFileName for other programs so i used GetModuleFileNameEx and EnumProcessModules. The big disadvantage is that non winnt versions dont have a GetModuleFileNameEx so you have to check the windows versions if its winnt or not .

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The toolhelp functions (CreateToolhelp32Snapshot) are available on 95/98/ME/2000/XP but not NT4.0.

    >> The big disadvantage is that non winnt versions dont have a GetModuleFileNameEx so you have to check the windows versions if its winnt or not <<

    I assume you already know this but not calling a function is not enough to ensure the program will work on platforms where that function does not exist. For example, this program will fail to load on Windows 9x:
    Code:
    if (isWinNT)
    {
        EnumProcessModules(...);
    }
    You can get true backwards compatibility you must use dynamic function loading. VC also has a feature that allows one to call a function normally but dynamic loading is used in the background called delayed loading.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    76

    johny145

    Yes i know, i use LoadLibrary and GetProcAddress on the psapi dll.
    But thanks anyway for the advise. Is there anyplace where i can find if psapidll is included in all winnt versions?.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. dont want to use all params
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 02-18-2003, 08:10 AM