C# 如何安装windows服务

C# 如何安装windows服务,c#,windows-services,C#,Windows Services,我有一个windows服务。 现在我想卸载它并重新安装,但如果我尝试使用以下命令安装它,则会出现此错误: InstallUtil.exe GestoreService.exe InstallUtil.exe GestoreService.exe 错误是 安装过程中发生了错误和异常。 System.ArgumentException:本地计算机中已存在Origin GestoreService 如何修复此错误 这是主要代码: public GestoreService() { Init

我有一个windows服务。 现在我想卸载它并重新安装,但如果我尝试使用以下命令安装它,则会出现此错误:

InstallUtil.exe GestoreService.exe
InstallUtil.exe GestoreService.exe
错误是

安装过程中发生了错误和异常。 System.ArgumentException:本地计算机中已存在Origin GestoreService

如何修复此错误

这是主要代码:

public GestoreService()
{
    InitializeComponent();
    try
    {
    if (!System.Diagnostics.EventLog.SourceExists("LoggerGestore"))
    {
        System.Diagnostics.EventLog.CreateEventSource(
        "LoggerGestore", "LoggerGestore");
    }
    }
    catch (Exception e)
    {
    log.Error(e);
    }

    log.Info("preparazione file di config in corso..."); 
}

在卸载已安装的服务之前,无法再次安装该服务。您需要使用/uninstall开关才能卸载服务,您可以在上了解有关installutil的更多信息

另请注意,如果要更新service.exe文件的某些库,则无需卸载并再次安装它。您所要做的就是停止服务,替换旧文件(Assemblies/.exe)并重新启动它

InstallUtil.exe GestoreService.exe /uninstall
或者您可以将
/uninstall
的缩写用作
/u

InstallUtil.exe /u GestoreService.exe

在卸载已安装的服务之前,无法再次安装该服务。您需要使用/uninstall开关才能卸载服务,您可以在上了解有关installutil的更多信息

另请注意,如果要更新service.exe文件的某些库,则无需卸载并再次安装它。您所要做的就是停止服务,替换旧文件(Assemblies/.exe)并重新启动它

InstallUtil.exe GestoreService.exe /uninstall
或者您可以将
/uninstall
的缩写用作
/u

InstallUtil.exe /u GestoreService.exe

首先卸载已安装的服务:

InstallUtil.exe /u GestoreService.exe
然后重新安装:


首先卸载已安装的服务:

InstallUtil.exe /u GestoreService.exe
然后重新安装: