1

Upon installation of a Windows Service, an application is using a custom action to set the ServiceName and DisplayName of that service according to whatever the user enters into an install dialog text box.

In testing this application it works fine for installation but when I try to uninstall the service I get an Error 1001. Service does not exist.

enter image description here

which is ultimately not true because I can run it. So my present thinking is that i need to somehow access the custom name of the service and feed that to the uninstaller. I would have thought this was all GUID based and that the name would become largely irrelevant re: uninstall but it would seem not to be the case.

So how to do I resolve this problem?

4

1 回答 1

2

我将假设您正在使用Installer派生类和ServiceInstaller实例。

我在一个项目中做了类似的事情。服务名称存储在一个文本文件中(这只是一个选项,但对我来说它是为了自动部署目的)。您可以将其存储在任何地方(注册表等)。

因此,您应该将在安装阶段配置的自定义服务名称保留在某个地方。

所以,我有我的Installer课:

[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer

在它的构造函数中,我这样做:

_process = new ServiceProcessInstaller { Account = ServiceAccount.LocalSystem };
_service = new ServiceInstaller { ServiceName = ServiceNameReader.GetServiceName(), StartType = ServiceStartMode.Automatic };
Installers.Add(_process);
Installers.Add(_service);

注意ServiceNameReader.GetServiceName()功能。此自定义函数从文件中获取服务名称。该类Installer也在卸载期间被实例化和调用。因此,如果您这样做,从某处动态加载实际服务名称,您将能够成功卸载它。

于 2012-06-24T06:43:30.307 回答