CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Executable Path

  1. #1
    Join Date
    Apr 1999
    Location
    Beaverton, OR
    Posts
    241

    Executable Path

    Can anybody tell me a good way to find the path of my executable? For example, if my program is located in D:\Manager\Manager\Debug\, is there a way to return the path name? I've looked through the documentation on the MSDN CD, and didn't find much. Thanks in advance.


  2. #2
    Join Date
    Apr 1999
    Posts
    5

    Re: Executable Path

    A maybe acceptable solution I can shortly think of is ::GetCurrentDirectory(..),
    but I guess this isn't 100 percent


  3. #3
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Executable Path

    The problem with GetCurrentDirectory is that when one creates a shortcut
    it is possible to start the executable in a directory other than where it resides.
    GetModuleFileName should be able to do what you need.



  4. #4
    Join Date
    Apr 1999
    Posts
    11

    Re: Executable Path

    Use GetCommandLine() to retrieve the entire path for the program. But I found out that the string returned by the GetCommandLine() acts a little different:
    If the program runs along, you will get the path, e.g.: "C:\Programs\Debug\myprog.exe" has extra '"' wrap the path. I guess the Win32 API wants to be able to display long directory names.

    If the program is launched by other program, the path won't have the extra '"'.

    You can try both cases to see the differences and watch out the '"'. Hope this will help. Good luck.

    Someone corrects me, if I am wrong.


    Allen


  5. #5
    Join Date
    Apr 1999
    Posts
    5

    Re: Executable Path

    Hi!

    Ofcourse you're right, that's what I ment with not 100 percent

    Thanks,

    Thomas


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

Featured