Reputation: 41
I have followed this guide: https://learn.microsoft.com/en-us/dotnet/core/extensions/windows-service-with-installer?tabs=ext And I chose the options to create an installer using the Microsoft Installer Extension.
It all works fine in that it can install the application as a service and so on.
But the issue comes to when it is time to uninstall it. As per the guide, I have added this if-statement that checks for the arguments like so:
if (args is { Length: 1 })
{
try
{
string executablePath =
Path.Combine(AppContext.BaseDirectory, "xxxx.exe");
if (args[0] is "/Install")
{
await Cli.Wrap("sc")
.WithArguments(["create", ServiceName, $"binPath={executablePath}", "start=auto"])
.ExecuteAsync();
}
else if (args[0] is "/Uninstall")
{
await Cli.Wrap("sc")
.WithArguments(["stop", ServiceName])
.ExecuteAsync();
await Cli.Wrap("sc")
.WithArguments(["delete", ServiceName])
.ExecuteAsync();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return;
}
Now My issue pertains to the Uninstall then.
I have made sure that I have added the custom actions as the guide says to do with the appropriate /Uninstall Arguments:
I do have more code underneath that if-statement for arguments that is used to actually run the application if no arguments are provided. But that shouldn't affect the installers functionality. I am also running the .msi as both regular user (which then prompts for admin later) and as admin itself. I have also uninstalled using the "Add or Remove Programs" feature in windows, but that also didn't work.
Anyone else had any issues with this and can provide some help as to why it won't remove the service entry?
AS of now, I have to manually open a terminal as admin and type sc.exe delete "ServiceName" which is a nuisance, but not the end of the world. But it definitely would be much better to solve this.
Upvotes: 0
Views: 39
Reputation: 708
Are you logging the uninstall? That should provide the answers. Once you have the log, search for all instances of RemoveService. Then check the few lines after each instance for clues.
In my experience with this it is almost always needing a reboot. Even if you're able to remove the service from the command line.
Upvotes: 0