How to install Windows Service

  • Thread starter Thread starter Shani
  • Start date Start date
S

Shani

Could someone suggest me as to how to install an
Windows Service in C#? I do not want to use InstallUtil
as I need to pass a parameter, which is not possible.
I do not want to use write an installer application
either. I want to install from Command Line prompt
from .NET and pass in different parameter values
hsomething
like,
ServiceName /Install
/ABC=""
/XYZ=""

Thank you in advance
-Shani
 
Shani said:
Could someone suggest me as to how to install an
Windows Service in C#? I do not want to use InstallUtil
as I need to pass a parameter, which is not possible.
I do not want to use write an installer application
either. I want to install from Command Line prompt
from .NET and pass in different parameter values
hsomething
like,
ServiceName /Install
/ABC=""
/XYZ=""

Use the ServiceInstaller class but, don't add the [RunInstaller] attribute.
Then, in your service's "main", look for the /Install parameter, if it's
present, create an instance of your ServiceInstaller based class and call
the .Install method.
 
John Vottero said:
Shani said:
Could someone suggest me as to how to install an
Windows Service in C#? I do not want to use InstallUtil
as I need to pass a parameter, which is not possible.
I do not want to use write an installer application
either. I want to install from Command Line prompt
from .NET and pass in different parameter values
hsomething
like,
ServiceName /Install
/ABC=""
/XYZ=""

Use the ServiceInstaller class but, don't add the [RunInstaller]
attribute. Then, in your service's "main", look for the /Install
parameter, if it's present, create an instance of your ServiceInstaller
based class and call the .Install method.

Actually, your class should be based upon Installer and it will contain a
ServiceInstaller and a ServiceProcessInstaller, just like the examples in
the doc. The key difference is that you will be creating an instance and
calling .Install instead of leaving that up to InstallUtil or some other
installer.
 
Back
Top