Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I detect that my application is running as service or in an interactive session?

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.

like image 770
bogdan Avatar asked Apr 19 '10 15:04

bogdan


1 Answers

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.

like image 141
Hongzi Avatar answered Sep 19 '22 08:09

Hongzi