views:

112

answers:

2

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!

+2  A: 

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
Thanks that works good enough!
Robert Gould
A: 

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

codymanix
yeah I know this but it goes against my requirement as stated in the question
Robert Gould