Installing multiple instances of the same windows service on a server

前端 未结 10 1700
深忆病人
深忆病人 2020-12-07 08:21

So we\'ve produced a windows service to feed data to our client application and everything is going great. The client has come up with a fun configuration request that requ

10条回答
  •  再見小時候
    2020-12-07 08:55

    Another quick way to specify a custom value for ServiceName and DisplayName is using installutil command line parameters.

    1. In your ProjectInstaller class override virtual methods Install(IDictionary stateSaver) and Uninstall(IDictionary savedState)

      public override void Install(System.Collections.IDictionary stateSaver)
      {
          GetCustomServiceName();
          base.Install(stateSaver);
      }
      
      public override void Uninstall(System.Collections.IDictionary savedState)
      {
          GetCustomServiceName();
          base.Uninstall(savedState);
      }
      
      //Retrieve custom service name from installutil command line parameters
      private void GetCustomServiceName()
      {
          string customServiceName = Context.Parameters["servicename"];
          if (!string.IsNullOrEmpty(customServiceName))
          {
              serviceInstaller1.ServiceName = customServiceName;
              serviceInstaller1.DisplayName = customServiceName;
          }
      }
      
    2. Build your project
    3. Install the service with installutil adding your custom name using /servicename parameter:

      installutil.exe /servicename="CustomServiceName" "c:\pathToService\SrvcExecutable.exe"
      

    Please note that if you do not specify /servicename in the command line the service will be installed with ServiceName and DisplayName values specified in ProjectInstaller properties/config

提交回复
热议问题