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

前端 未结 5 1433
我寻月下人不归
我寻月下人不归 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

    If your application is running as a console application (when not running as a service), a simple solution is to check whether a console has been allocated:

    if(GetConsoleWindow())
    {
        //Running as console Application
    }
    else
    {
        //Running as Service
    }
    

提交回复
热议问题