Windows服务,如何从VS安装项目中卸载?

时间:2021-11-04 17:06:05

I have created a windows service, it works great, but as soon as I try to install the service, it removed the directory, however, the service did not get removed, and when I try to install the service again, it give me an error 1001: Service already exists. How can I fix that?

我已经创建了一个Windows服务,它运行良好,但是一旦我尝试安装该服务,它就删除了目录,但是,服务没有被删除,当我尝试再次安装服务时,它给了我一个错误1001:服务已存在。我该如何解决这个问题?

And also, is there any code for me to remove the service when I uninstall the project?

而且,当我卸载项目时,是否有任何代码可以删除该服务?

Thanks

3 个解决方案

#1


You can use installutil.exe to install or uninstall a service from the command line.

您可以使用installutil.exe从命令行安装或卸载服务。

To install: installutil yourproject.exe

要安装:installutil yourproject.exe

To uninstall: installutil /u yourproject.exe

要卸载:installutil / u yourproject.exe

You can also use sc delete from the command line. Type sc by itself to get the list of parameters.

您也可以从命令行使用sc delete。单独键入sc以获取参数列表。

Lastly you can use the ServiceInstaller.Uninstall() method if you're using the predefined installation component. You'll have to call it from the Uninstall handler of your installer.

最后,如果您使用的是预定义的安装组件,则可以使用ServiceInstaller.Uninstall()方法。您必须从安装程序的Uninstall处理程序中调用它。

#2


You might need to remove it from the registry at [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services]

您可能需要在[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services]中将其从注册表中删除

#3


Have a look at this post. It references another one, so, between them, they may have your solution.

看看这篇文章。它引用了另一个,因此,在它们之间,它们可能有你的解决方案。

#1


You can use installutil.exe to install or uninstall a service from the command line.

您可以使用installutil.exe从命令行安装或卸载服务。

To install: installutil yourproject.exe

要安装:installutil yourproject.exe

To uninstall: installutil /u yourproject.exe

要卸载:installutil / u yourproject.exe

You can also use sc delete from the command line. Type sc by itself to get the list of parameters.

您也可以从命令行使用sc delete。单独键入sc以获取参数列表。

Lastly you can use the ServiceInstaller.Uninstall() method if you're using the predefined installation component. You'll have to call it from the Uninstall handler of your installer.

最后,如果您使用的是预定义的安装组件,则可以使用ServiceInstaller.Uninstall()方法。您必须从安装程序的Uninstall处理程序中调用它。

#2


You might need to remove it from the registry at [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services]

您可能需要在[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services]中将其从注册表中删除

#3


Have a look at this post. It references another one, so, between them, they may have your solution.

看看这篇文章。它引用了另一个,因此,在它们之间,它们可能有你的解决方案。