为什么我不能安装我的 windows 服务 - 指定的服务已经存在
Why can't I install my windows service - Specified service already exists
我希望此时我能在我的电脑上放一枚手榴弹。我很沮丧,因为我不明白为什么我的应用程序不能使用 installUtil 安装。
我刚刚浏览了这个 link 现在:Windows Service Install Ends in Rollback 不幸的是,那里的善意建议对我的情况没有帮助,在考虑所有因素后产生了以下错误SO 的好人在 link 和其他人上发布的答案。
我已经在网上寻找任务并行处理模式的最佳实践,但目前没有任何帮助。我在尝试安装时遇到的最新错误如下:
.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();
}
}
最后编译的安装文件我也设置了编译模式为release
我已经完成 "sc delete Servie V2" 并且我还检查了服务控制台,但那里没有列出此类服务。
我也尝试过InstallUtil.exe -u 命令卸载,但我仍然得到这个愚蠢的错误。我现在该怎么办?
确保您的 Program.cs
文件看起来像这样:
static class Program
{
static void Main()
{
var service = new YourServiceName();
ServiceBase.Run(service);
}
}
在 InitializeComponent()
方法中确保 ServiceName
属性 值与 ProjectInstaller.cs
中的 ServiceName
相同
this.ServiceName = "MyServiceName";//in the YourServiceName partial class
this.myServiceInstaller.ServiceName = "MyServiceName";//in the installer
确保只有一个安装程序。
在您创建的用于安装和卸载服务的批处理文件中,确保您指向正确的 InstallUtil.exe
。
对于 64 位架构,您可以使用 - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe
对于 32 位架构,您可以使用 - C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
示例 InstallService.bat 文件:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe" "PathToTheExecutables\MyServiceName.exe"
暂停
示例 UninstallService.bat 文件:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe" /u "PathToTheExecutables\MyServiceName.exe"
暂停
确保您 运行 以管理员身份执行命令:)
我希望此时我能在我的电脑上放一枚手榴弹。我很沮丧,因为我不明白为什么我的应用程序不能使用 installUtil 安装。
我刚刚浏览了这个 link 现在:Windows Service Install Ends in Rollback 不幸的是,那里的善意建议对我的情况没有帮助,在考虑所有因素后产生了以下错误SO 的好人在 link 和其他人上发布的答案。
我已经在网上寻找任务并行处理模式的最佳实践,但目前没有任何帮助。我在尝试安装时遇到的最新错误如下:
.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();
}
}
最后编译的安装文件我也设置了编译模式为release
我已经完成 "sc delete Servie V2" 并且我还检查了服务控制台,但那里没有列出此类服务。
我也尝试过InstallUtil.exe -u 命令卸载,但我仍然得到这个愚蠢的错误。我现在该怎么办?
确保您的
Program.cs
文件看起来像这样:static class Program { static void Main() { var service = new YourServiceName(); ServiceBase.Run(service); } }
在
InitializeComponent()
方法中确保ServiceName
属性 值与ProjectInstaller.cs
中的ServiceName
相同this.ServiceName = "MyServiceName";//in the YourServiceName partial class this.myServiceInstaller.ServiceName = "MyServiceName";//in the installer
确保只有一个安装程序。
在您创建的用于安装和卸载服务的批处理文件中,确保您指向正确的
InstallUtil.exe
。对于 64 位架构,您可以使用 - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe
对于 32 位架构,您可以使用 - C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe
示例 InstallService.bat 文件:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe" "PathToTheExecutables\MyServiceName.exe" 暂停
示例 UninstallService.bat 文件:
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe" /u "PathToTheExecutables\MyServiceName.exe" 暂停
确保您 运行 以管理员身份执行命令:)