I am developing a C# windows service + UI application.
I have a problem that if during the uninstall process the user is trying to launch the UI then the uninstall gets corrupted and stuck (because the ui holds handles to some files and prevents them from getting deleted).
What is the best way to handle this situation? I thought that maybe I should strict the access to the .exe when I am starting the uninstall process, so the user won't be able to launch it.
But I was wondering if there is a BKM of how to do that
The application is already installed on customers' machines, So I can't make any changes to the application itself.
I have an upgrade installer that can do stuff as part of the uninstallation process. The upgrade installer first uninstall the application and then reinstall it. I can add code only to the upgrade installer so I can't use a mutex for example. Thanks!
You can use named mutex, it is windows core object and two processes can check if it is already registered or not.
While uninstalling just create a named mutex, and check if it exists on process start
Here is how to create named mutex
Here is how to check if it exists