Reinstall service with another name

3

Currently I have a service (Service 1) of windows working correctly. I have made an improvement and I have called it Service 2 and I want to install it, but I want to stop Service 1 first and then install and launch Service 2 to see if it fails to stop Service 2 immediately and restart Service 1.

I have tried to change all the ProductCode, the Guid of the AssemblyInfo, the name, description and others of Service 2.

However, when I installed it, I missed error 1001 indicating that this service already exists ...

Someone could tell me that I have to change in Service 2 so that the system understands that it is a completely new service.

Thank you very much for the help.

    
asked by U. Busto 09.01.2018 в 14:50
source

2 answers

0

You should change the property ServiceInstaller.ServiceName . This property indicates the name used by the system to identify this service. This property must be identical to the ServiceBase.ServiceName of the service that you want to install. By default this property is found in the corresponding InitializeComponent method in% service Designer.cs . I show a screenshot

    
answered by 10.01.2018 в 11:45
-2

1001 the service already exists, the uninstallation of the service if it is done by setup, requires restart windows. I use Topshelf

It has great advantages:

  • Create a windows service with a console application.
  • Debug without hassle of permissions.
  • Manage the service by commands (installation, service name, etc.) ..., uninstall)
  • It is integrated with more known loggers, lognet, serilog ...

    public class TownCrier
    {
      readonly Timer _timer;
      public TownCrier()
    {
    _timer = new Timer(1000) {AutoReset = true};
    _timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} 
    and all is well", DateTime.Now);
    }
    public void Start() { _timer.Start(); }
    public void Stop() { _timer.Stop(); }
    }
    
    public class Program
    {
    public static void Main()
    {
    var rc = HostFactory.Run(x =>                                   //1
    {
        x.Service<TownCrier>(s =>                                   //2
        {
           s.ConstructUsing(name=> new TownCrier());                //3
           s.WhenStarted(tc => tc.Start());                         //4
           s.WhenStopped(tc => tc.Stop());                          //5
        });
        x.RunAsLocalSystem();                                       //6
    
        x.SetDescription("Sample Topshelf Host");                   //7
        x.SetDisplayName("Stuff");                                  //8
        x.SetServiceName("Stuff");                                  //9
    });                                                             //10
    
    var exitCode = (int) Convert.ChangeType(rc, rc.GetTypeCode());  //11
    Environment.ExitCode = exitCode;
    }
    }
    
answered by 09.01.2018 в 16:21