2

I'm trying to get the directory where the executable is.

On debian, I know I can get the pid and do a "realpath" on /proc/[pid]/exe in order to have the absolute path. But I'm stuck on windows, because I don't know how to do. I want something usable on Windows 7 and upper.

GetCurrentDirectory doens't give me this information, since if the program is run from command-line, the current directory is not necessarly the rigth one.

My program will be a windows service, so it's even more true.

I can't use command line argument (like argv[0] or else) to determine the program's name or location. edit : My program is not necessarly in $PATH, so I can't use "where".

Is there a Windows API function that I have missed ? Or do I need to search like on Debian ?

Tom's
  • 2,448
  • 10
  • 22
  • 2
    another dup: https://stackoverflow.com/questions/9112893/how-to-get-path-to-executable-in-c-running-on-windows – bolov Jan 29 '18 at 14:12
  • GetModuleFileName !!! Thank ! I found a large number of answer with "where.exe" but nothing with GetModuleFileName. I must have not searched with the rigth key word. – Tom's Jan 29 '18 at 14:14

0 Answers0