CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2006
    Location
    Croatia - Zagreb
    Posts
    459

    How to get folder path, where *.exe is running? (win32)

    In other words, I have some exe file, and when user executes program, it must read the folder where it is currently located so I can know where to set global variable path.

    Some might say that this can be easy by setting global environment path of windows, but however this is not the case (probably couse it's win32), and that works perfectly when developing, but in release run-time this fails.
    Wherever path is set windows, cant see my conf files, so i need to know exact working dir.
    Thanks.
    You just divided by zero, didn't you?

  2. #2
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    Re: How to get folder path, where *.exe is running? (win32)

    Take a look at GetModuleFileName.Pass NULL as hModule parameter.
    - Guido

  3. #3
    Join Date
    Sep 2003
    Posts
    22

    Re: How to get folder path, where *.exe is running? (win32)

    the function GetCurrentDirectory may do the trick

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: How to get folder path, where *.exe is running? (win32)

    Quote Originally Posted by innovaltec
    the function GetCurrentDirectory may do the trick
    Somtimes not ! Some applications change their working directory.
    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    Feb 2006
    Location
    Croatia - Zagreb
    Posts
    459

    Re: How to get folder path, where *.exe is running? (win32)

    thanks, GetCurrentDirectory worked like a charm
    I knew that there is some func. that does this, but I just could rember.
    Thanks.
    You just divided by zero, didn't you?

  6. #6
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: How to get folder path, where *.exe is running? (win32)

    I would use GetModuleFileName like GNiewerth suggested.

    GetCurrentDirectory does not always return the folder which contains the EXE.
    My hobby projects:
    www.rclsoftware.org.uk

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