views:

209

answers:

2

I have a few Windows Services written in C# that I have setup to support being run from the command line as a console app if a specific parameter is passed. Works great but I would love to be able to detect whether the app is being run by the service control mananger or from a command line.

Is there any way to tell at runtime if my app was started by the SCM?

+1  A: 

The SCM will call your OnStart method, so you could mark that event and make sure when you run from the command line, you don't call OnStart. Or, you could check the startup parameters to see how the application was started.

JP Alioto
+1  A: 

Environment.UserInteractive will return false if the process is running under the SCM.

guardi
This works nicely as long as you do not enable the 'Allow service to interact with the desktop' option in the SCM. Not a problem for our services. Thanks Guardi!
BrettRobi