MSI application uninstall not working properly after windows update

Test Admin 176 Reputation points
2024-09-12T06:16:40.4833333+00:00

While uninstalling our MSI Application, we have shown a custom exception message when MSI application is running in the background.

To show custom message we have override the installer file .

namespace SampleApplication

{

[RunInstaller(true)]

public partial class SampleInstaller : System.Configuration.Install.Installer

{

    public override void Uninstall(IDictionary savedState)

    {

        if (AlreadyRunning())

        {

    // custom exception we throw 

            throw new InstallException("Sample MSI is running in background. Please close if you want to uninstall.");

        }

        else

        {

            base.Uninstall(savedState);

            try

            {

                //other tasks

            }

            catch (Exception exception)

            {

                // error occured                    

        }

    }   

    private static bool AlreadyRunning()

    {

        Process[] processes = Process.GetProcessesByName("SampleMSI");

        if (processes.Length > 0)

        {

            foreach (Process proc in processes)

            {

                var currentSessionID = Process.GetCurrentProcess().SessionId;

                if (proc.SessionId == currentSessionID)

                {

                    return true;

                }

            }

        }

        return false;

    }

}
```}

Issue:

We think after windows update(Windows 10 and Windows 11)only this issue is occurring, when we uninstall the MSI application when running in background, the above custom exception is displayed and parallelly the application is removed from the Control Panel's "Programs and Features", but other associated files are not removed.

Unlike previous windows versions, where the uninstallation process would stop when application running in background and app is not removed from Programs and Features.

Is there any problem with the above override installer code and is there any update related Windows Installer in windows update?

Kindly help us to solve this issue
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,427 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,962 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.