Wednesday, August 29, 2018

Multiple instances of same windows service on one server

Its possible to host multiple windows service on same server but different name. Here's the link to do it.

Just a small tweak in the code:

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            RetrieveServiceName();
            base.Install(stateSaver);
        }

        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            RetrieveServiceName();
            base.Uninstall(savedState);
        }

        private void RetrieveServiceName()
        {
            var serviceName = Context.Parameters["servicename"];
            if (!string.IsNullOrEmpty(serviceName))
            {
                this._serviceInstaller.ServiceName = serviceName;
                this._serviceInstaller.DisplayName = serviceName;
            }
        }

We can now use this like this:
installutil /servicename=”My Service [SysTest]” d:\pathToMyService\Service.exe
and for uninstall:
installutil /u /servicename=”My Service [SysTest]” d:\pathToMyService\Service.exe
Note for the uninstall you need to supply the servicename so windows how to resolve the service to uninstall

No comments:

Post a Comment