How do we tell if a C++ application is launched as a Windows service?

前端 未结 5 1438
我寻月下人不归
我寻月下人不归 2020-12-16 04:55

We have a console app which we launch from command prompt for debugging, but we also launch this as an NT service for production.

Right now, the code has this logic:<

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 05:10

    Would checking a user account help you? IIRC a service would be run as system account or something very similar and I assume you run your application in debug mode under your normal user account. I think OpenProcessToken and GetTokenInformation with TokenUser functions would help here.

提交回复
热议问题