gpt4 book ai didi

c# - 为什么我无法安装我的 Windows 服务 - 指定的服务已经存在

转载 作者:太空狗 更新时间:2023-10-30 00:38:48 25 4
gpt4 key购买 nike

我希望此时我能在我的电脑上放一枚手榴弹。我很沮丧,因为我不明白为什么我的应用程序无法使用 installUtil 安装。

我刚刚浏览了这个链接:Windows Service Install Ends in Rollback不幸的是,那里的善意建议对我的情况没有帮助,在考虑了 SO 的好人在该链接和其他人上发布的所有答案后,产生了以下错误。

我在网络上寻找过任务并行处理模式的最佳实践,但目前没有任何帮助。我在尝试安装时遇到的最新错误如下:

.exe assembly's progress. The file is located at E:\xxx\MyService\Service_V2.InstallLog. Installing assembly 'E:\xxx\MyService\Service_V2.exe'. Affected parameters are:
logtoconsole = logfile = E:\xxx\MyService\Service_V2.InstallLog
assemblypath = E:\xxx\MyService\Service_V2.exe Installing service Service V2... Service Service V2 has been successfully installed. Creating EventLog source Service V2 in log Application... Installing service Service V2... Creating EventLog source Service V2 in log Application...

An exception occurred during the Install phase. System.ComponentModel.Win32Exception: The specified service already exists

The Rollback phase of the installation is beginning. See the contents of the log file for the E:\xxx\MyService\Service_V2 .exe assembly's progress. The file is located at E:\xxx\MyService\Service_V2.InstallLog. Rolling back assembly 'E:\xxx\MyService\Service_V2.exe'. Affected parameters are:
logtoconsole = logfile = E:\xxx\MyService\Service_V2.InstallLog
assemblypath = E:\xxx\MyService\Service_V2.exe Restoring event log to previous state for source Service V2. Restoring event log to previous state for source Service V2. Service Service V2 is being removed from the system... Service Service V2 was successfully removed from the system.

The Rollback phase completed successfully.

The transacted install has completed. The installation failed, and the rollback has been performed.

也没有任何内容写入事件日志。

这是我的 OnStart() 方法:

protected override void OnStart(string[] args)
{
var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;

ErrorLogFileName = "Service_V2Errors" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
Service_V2LogFile = "Service_V2Log" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";

ErrorLogPath = ConfigurationManager.AppSettings["Errorpath"].ToString();
CheckBatchRecord = Convert.ToInt32(ConfigurationManager.AppSettings["CheckBatchTime"].ToString());

if (!Directory.Exists(ErrorLogPath))
{
Directory.CreateDirectory(ErrorLogPath);
}

LogMessage("Starting Service " + DateTime.Now.ToString());

_ErrorLog = new StreamWriter(ErrorLogPath + "//" + ErrorLogFileName, true);
_ErrorLog.WriteLine("Error, Location, AdditionalInformation", true);
_ErrorLog.Close();

var t = Task.Run(() => Service_V2Start(), token);

try
{
t.Wait();
}
catch (AggregateException e)
{
LogMessage("Exception messages:");
foreach (var ie in e.InnerExceptions)
LogMessage(ie.GetType().Name + " : " + ie.Message);

LogMessage("\nTask status: " + t.Status);
}
finally
{
tokenSource.Dispose();
}
}

我还为编译的最终安装文件设置了编译模式。

我已经执行了“sc delete Servie V2”,我还检查了服务控制台,但那里没有列出此类服务。

我也试过 InstallUtil.exe -u 命令来卸载,但我仍然得到这个傻瓜错误。我现在该怎么办?

最佳答案

  1. 确保您的 Program.cs 文件看起来像这样:

    static class Program
    {
    static void Main()
    {
    var service = new YourServiceName();
    ServiceBase.Run(service);
    }
    }
  2. InitializeComponent() 方法中,确保 ServiceName 属性值与 中的 ServiceName 相同>ProjectInstaller.cs

     this.ServiceName = "MyServiceName";//in the YourServiceName partial class

    this.myServiceInstaller.ServiceName = "MyServiceName";//in the installer
  3. 确保您只有一个安装程序。

  4. 在您创建的用于安装和卸载服务的批处理文件中,确保您指向正确的 InstallUtil.exe

    对于 64 位架构,您可以使用 - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe

    对于 32 位架构,您可以使用 - C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe

  5. 示例 InstallService.bat 文件:

    "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe""PathToTheExecutables\MyServiceName.exe"暂停

  6. 示例 UninstallService.bat 文件:

    "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe"/u "PathToTheExecutables\MyServiceName.exe"暂停

关于c# - 为什么我无法安装我的 Windows 服务 - 指定的服务已经存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38220645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com