How can I tell if I'm running as a service?
-
I have an application that should be able to run either as a service or as a user mode application. Currently, I call StartServiceCtrlDispatcher and if it fails (error 1063) I run as user mode. But, StartServiceCtrlDispatcher often takes several seconds before it fails when I'm running the app in user mode, causing an annoying startup delay. Can someone suggest a fast way to tell whether or not my application is being started as a service? (Please do not suggest using command line options.) -------- There are 10 types of people in this world. Those who know binary and those who don't.
-
I have an application that should be able to run either as a service or as a user mode application. Currently, I call StartServiceCtrlDispatcher and if it fails (error 1063) I run as user mode. But, StartServiceCtrlDispatcher often takes several seconds before it fails when I'm running the app in user mode, causing an annoying startup delay. Can someone suggest a fast way to tell whether or not my application is being started as a service? (Please do not suggest using command line options.) -------- There are 10 types of people in this world. Those who know binary and those who don't.
JT Anderson wrote: Can someone suggest a fast way to tell whether or not my application is being started as a service? (Please do not suggest using command line options.) I'm not sure what you've got against command line options - it would be the simplest solution... You could call
GetProcessWindowStation()
and if it returns NULL, it is probably either running as a service or as a WTS process. If it is not NULL, then it was probably started by the user. Not perfect though. Another way would be to get the user name that the process was started as. Generally services are run as the "Local Service" user (or something similar, can't remember exactly).Ryan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"