如何解决安装 Windows 服务时出现错误 1001
我在安装 Windows 服务时遇到以下错误。
错误 1001。在安装的提交阶段发生异常。该异常将被忽略并继续安装。但是,安装完成后应用程序可能无法正常运行 -->无法在计算机上启动服务 ACSERVICE2'。'。-->该服务未及时响应启动或控制请求。
感谢任何帮助...
代码是:
protected override void OnStart(string[] args)
{
try
{
AC_Main objMain = new AC_Main();
td=new Thread(new ThreadStart(objMain.Main));
td.IsBackground = true;
td.Start();
eLog.WriteEntry("Service Started at :" + System.DateTime.Now.ToString());
}
catch(System.Security.SecurityException exc)
{
}
}
protected override void OnStop()
{
td.Abort();
eLog.WriteEntry("Service Stopped at :" + System.DateTime.Now.ToString());
}
提交的方法是:
private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
{
serviceController.ServiceName = "ACSERVICE2";
ConnectionOptions coOptions = new ConnectionOptions();
coOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
mgmtScope.Connect();
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" + this.serviceController.ServiceName + "'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
this.serviceController.Start();
}
I am getting following error while installing windows service.
Error 1001 . An Exception occurred during the commit phase of the installation. This exception will be ignored and installation will continue. However , the application might not function correctly after installation is complete --> Cannot start service ACSERVICE2 on Computer'.'.-->The service did not respond to the start or control request in a timely fashion.
Any help is appreciated...
Code is :
protected override void OnStart(string[] args)
{
try
{
AC_Main objMain = new AC_Main();
td=new Thread(new ThreadStart(objMain.Main));
td.IsBackground = true;
td.Start();
eLog.WriteEntry("Service Started at :" + System.DateTime.Now.ToString());
}
catch(System.Security.SecurityException exc)
{
}
}
protected override void OnStop()
{
td.Abort();
eLog.WriteEntry("Service Stopped at :" + System.DateTime.Now.ToString());
}
Committed Method is :
private void ProjectInstaller_Committed(object sender, InstallEventArgs e)
{
serviceController.ServiceName = "ACSERVICE2";
ConnectionOptions coOptions = new ConnectionOptions();
coOptions.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope mgmtScope = new System.Management.ManagementScope(@"root\CIMV2", coOptions);
mgmtScope.Connect();
ManagementObject wmiService;
wmiService = new ManagementObject("Win32_Service.Name='" + this.serviceController.ServiceName + "'");
ManagementBaseObject InParam = wmiService.GetMethodParameters("Change");
InParam["DesktopInteract"] = true;
ManagementBaseObject OutParam = wmiService.InvokeMethod("Change", InParam, null);
this.serviceController.Start();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您永远不应该捕获错误然后忽略它。
那可能是你的问题。如果您向 catch 块添加一些日志记录,会发生什么情况,类似这样?
You should never catch an error and then ignore it.
That might be your problem. What happens if you add some logging to the catch block, something like this?
是的,如果您没有正确卸载尝试再次安装的服务,就会发生这种情况。几天前我也遇到了同样的问题。我创建了新项目,复制了相同的代码并从头开始再次安装该服务。
我的问题是
Yes, this happens if you didn't correctly uninstall the service you are trying to install again. I had the same problem a few days ago. I created new project, copied the same code and installed the service again from scratch.
My problem was that