ServiceInstaller.Uninstall不会停止Windows 10上的服务

时间:2017-11-15 17:33:02

标签: c# windows windows-services

有一种奇怪的行为。

我有以下代码:

ServiceInstaller serviceInstaller = new ServiceInstaller();
InstallContext installContext = new InstallContext();
serviceInstaller.Context = installContext;
serviceInstaller.ServiceName = strServiceName;
serviceInstaller.Uninstall(null);

Windows 7上的一切正常,但它在Windows 10上无效。

我必须明确停止服务(ServiceController.Stop()),以便能够在Windows 10上卸载它。

如MSDN中所述,ServiceInstaller.Uninstall ()尝试停止服务,但如果停止失败,则会继续正常工作。

  

首先尝试在卸载服务之前停止服务。   如果服务无法停止,则不会捕获任何异常,并且   方法继续删除服务。

在Windows 7和Windows 10中停止线程有什么区别吗?或者ServiceInstaller.Uninstall ()可能不试图在Windows 10上停止服务?

0 个答案:

没有答案