I've got a windows service, built using C#, that is installed via a VS2008 setup project, and am having a couple of problems occurring with the uninstall process:
Service is not stopped prior to uninstalling
When the uninstall routine runs, it throws up an error about files being in use. Clicking continue completes the installer correctly, but the service still shows up in the list, so it's not being uninstalled properly.
(At present, I have to resort to deleting it manually using sc delete servicename).
I'm trying to stop the service before uninstalling using the following code, but it doesn't seem to be taking effect:
protected override void OnBeforeUninstall(IDictionary savedState)
{
base.OnBeforeUninstall(savedState);
ServiceController serviceController = new ServiceController(MyInstaller.ServiceName);
serviceController.Stop();
}
When is this code called, and how can I stop the service prior to uninstalling?
Installation folder not deleted after uninstalling
The application also creates some files within it's installation folder when executed. After uninstalling, the installation folder (C:\Program Files\MyApp) is not deleted, and contains the files created by the application, though all other files that were actually installed by the installer have been deleted successfully.
Is it possible for the uninstall process to delete the installation folder, including all generated files within that folder, and if so, how?
Thanks.