0

I'm developing an orthogonal. Reporting/Logging system for several applications and was wondering how I can get an applications name on Windows using C/C++? the obvious requirement is I can't get it as a commandline argument or have the application tell me directly so I need to query the OS.

Thanks for any ideas!

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
  • Dupe of http://stackoverflow.com/questions/124886/how-to-get-the-application-executable-name-in-windows-c-win32-or-c-cli among others –  Jun 05 '09 at 16:53
  • Thanks too. The suggestion engine didn't say anything when I was asking (not in the top 5 or so atleast). – Robert Gould Jun 05 '09 at 16:56

2 Answers2

3

You could try the following. Call GetModuleHandle passing in NULL. This will give you back the handle for the .exe of the current running process. You can then use GetModuleFileName method to get the name of the actual file. That should serve as a good "program name"

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
0

normally the program name is passed to the main() function as argv[0].

codymanix
  • 28,510
  • 21
  • 92
  • 151