I'm writing an application that is able to run as a service or standalone but I want to detect if the application was executed as a service or in a normal user session.
If this is a C++ application, somewhere in your startup code you have to call StartServiceCtrlDispatcher. If it fails and GetLastError()
returns ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
, the app has not been started as a service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With