I have a Windows service exe that derives from
System.Configuration.Install.Installer

The exe can be executed from the command line with parameters such as
INSTALL, UNINSTALL, START, and STOP to perform such tasks on the service

But the exe is also the exe that _is_ the service process, so when it's run
with no parameters (by the SCM?) it calls
System.ServiceProcess.ServiceBase.Run ( srp.ServicesToRun ) ;

The problem then is when it's accidently run with no parameters from the
command line.

Is there some way for it to know whether or not it's being executed by the
SCM? I'd like it to be able to give a help message and terminate when it's
run from the command line while still behaving properly when running as a
service.

Re: System.Configuration.Install.Installer and console by Dmytro

Dmytro
Thu Mar 23 05:06:49 CST 2006

You can analyze the command line arguments at startup, and configure the
service entry in the SCM that it runs your exe with a specific argument, say
"-service". If no command-line args are supplied, don't run
System.ServiceProcess.ServiceBase.Run, but display a help message instead.

"PIEBALD" <PIEBALD@discussions.microsoft.com> wrote in message
news:8185E0B7-2741-40B4-BB2C-B7666A5A5407@microsoft.com...
>I have a Windows service exe that derives from
> System.Configuration.Install.Installer
>
> The exe can be executed from the command line with parameters such as
> INSTALL, UNINSTALL, START, and STOP to perform such tasks on the service
>
> But the exe is also the exe that _is_ the service process, so when it's
> run
> with no parameters (by the SCM?) it calls
> System.ServiceProcess.ServiceBase.Run ( srp.ServicesToRun ) ;
>
> The problem then is when it's accidently run with no parameters from the
> command line.
>
> Is there some way for it to know whether or not it's being executed by the
> SCM? I'd like it to be able to give a help message and terminate when it's
> run from the command line while still behaving properly when running as a
> service.


Re: System.Configuration.Install.Installer and console by PIEBALD

PIEBALD
Thu Mar 23 09:19:36 CST 2006

> You can analyze the command line arguments at startup, and configure the
> service entry in the SCM that it runs your exe with a specific argument, say
> "-service". If no command-line args are supplied, don't run

That seems a bit kludgy and I don't see where to do it anyway.

I've looked through the properties and methods for:
System.Configuration.Install.Installer
System.ServiceProcess.ServiceProcessInstaller
System.ServiceProcess.ServiceInstaller
System.ServiceProcess.ServiceBase

and not seen anything like a place to put parameters. Nor any way for
INSTALLUTIL to pass them.


RE: System.Configuration.Install.Installer and console by PIEBALD

PIEBALD
Thu Mar 23 09:33:29 CST 2006

I got it...

System.Environment.UserInteractive