How to pass parameters to Windows Service?

You can use configuration file, Registry or any type of databases.


You are going to have to load these values up from an external source. The easiest is to load them directly from an app.config file, using the Configuration Manager. Something like this: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx


You can pass parameters on startup like this:

  1. Right click on MyComputer and select Manage -> Services and Applications -> Services
  2. Right click on your service, select Properties and you should then see the Start Parameters box under the General tab.

If you enter there for example User Password you will get these parameters in protected override void OnStart(string[] args) as args. then use it like this:

protected override void OnStart(string[] args)
{
    base.OnStart(args);
    UserName = args[0];
    Password = args[1];
    //do everything else
}