简体   繁体   中英

Deleting windows service for installer does not work

I'm trying to deinstall a windows service, but I get the following message.

在此处输入图片说明

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 doesn't do any checks because you are going out of process and not using native MSI functionality. The installer would be simpler and reliable if you used the built in ServiceInstall and ServiceControl tables instead of reinventing the wheel.

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.

But there are other solutions to remove a service:

Option 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)

Open the registery and navigate to: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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