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.
我正在开发一个正交。针对多个应用程序的报告/日志记录系统,并想知道如何使用C / C ++在Windows上获取应用程序名称?显而易见的要求是我无法将其作为命令行参数或让应用程序直接告诉我,所以我需要查询操作系统。
Thanks for any ideas!
谢谢你的任何想法!
2 个解决方案
#1
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"
您可以尝试以下方法。调用GetModuleHandle传入NULL。这将返回当前正在运行的进程的.exe句柄。然后,您可以使用GetModuleFileName方法获取实际文件的名称。这应该是一个很好的“程序名称”
#2
normally the program name is passed to the main() function as argv[0].
通常程序名称作为argv [0]传递给main()函数。
#1
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"
您可以尝试以下方法。调用GetModuleHandle传入NULL。这将返回当前正在运行的进程的.exe句柄。然后,您可以使用GetModuleFileName方法获取实际文件的名称。这应该是一个很好的“程序名称”
#2
normally the program name is passed to the main() function as argv[0].
通常程序名称作为argv [0]传递给main()函数。