简体   繁体   English

删除安装程序的Windows服务不起作用

[英]Deleting windows service for installer does not work

I'm trying to deinstall a windows service, but I get the following message. 我正在尝试卸载Windows服务,但收到以下消息。

在此处输入图片说明

So I think ok it's deleted. 所以我认为确定已删除。 But when I check my service window it's still there.. Anyone know what I am doing wrong ? 但是,当我检查服务窗口时,它仍然存在。有人知道我做错了吗? I'll attach my code below. 我将在下面附加我的代码。

[RunInstaller(true)]
public partial class ProjectInstaller : System.Configuration.Install.Installer
{
    public ErrorLogging errLog { get; set; }
    public ProjectInstaller()
    {
        errLog = new ErrorLogging();
        InitializeComponent();
    }

    protected override void OnBeforeInstall(IDictionary savedState)
    {
        base.OnBeforeInstall(savedState);

        try
        {
              /* Some folder creation happens here */
        }
        catch (InstallException ex)
        {
            errLog.WriteToErrorLog(ex.Message, ex.StackTrace, "Creating directories failed");
        }
    }
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
    }

    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
    }
}

What I have tried: 我试过的

  • Rebooting 重新启动
  • Deleting the installer class but then the MSI installer doesn't do my checks 删除安装程序类,但随后MSI安装程序不执行我的检查

MSI doesn't do any checks because you are going out of process and not using native MSI functionality. MSI不会进行任何检查,因为您将无法进行处理且未使用本机MSI功能。 The installer would be simpler and reliable if you used the built in ServiceInstall and ServiceControl tables instead of reinventing the wheel. 如果您使用内置的ServiceInstall和ServiceControl表而不是重新发明轮子,则安装程序将更加简单可靠。

Assuming your question is not about code, and that you're just trying to remove the service from that machine: 假设您的问题与代码无关,而您只是想从该计算机上删除服务:

  1. An Elevated Command Prompt might be needed (If you don't know how to open one, here's how ). 提升的命令提示符可能需要(如果你不知道如何打开一个, 这里是如何 )。
  2. If that doesn't help, there is a service deletion command: 如果这样做没有帮助,请执行服务删除命令:

    sc delete ServiceName

It seems from you code, that you just want to uninstall, but that it fails for whatever reason if you use InstallUtil. 从您的代码看来,您只想卸载,但是如果使用InstallUtil,则无论出于何种原因它都会失败。

But there are other solutions to remove a service: 但是还有其他解决方案来删除服务:

Option 1: (sc.exe) 选项1:(sc.exe)

Open a command prompt (you might need to open it as an administrator and execute: 打开命令提示符(您可能需要以管理员身份打开它并执行:

sc delete ServiceName

Note: If your service name contains some spaced, you need to wrap it: 注意:如果您的服务名称包含一些空格,则需要将其包装:

sc delete "My service name with spaces"

Option 2: (Regedit) 选项2:(Regedit)

Open the registery and navigate to: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services 打开注册表并导航到: HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ Services

Find your service here, delete it and reboot the system. 在此处找到您的服务,将其删除并重新启动系统。

That are 2 options that you have to remove a Service without using InstallUtil 这是不使用InstallUtil即可删除服务的2个选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM