A community member has associated this post with a similar question:
MSI application not uninstalled properly after update to latest windows 10 version

Only moderators can edit this content.

Regarding overriding the installer file to show custom exception when MSI application running in background

Test Admin 171 Reputation points
2024-06-20T13:19:18.1333333+00:00

While uninstalling the 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:

In Recent windows update(Windows 10 and Windows 11), 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.

Then we have closed the background running application and try to install or uninstall again, the below error message is displayed and we can't completely uninstall or remove the installed MSI.

"This advertised application is unsafe and will not be installed. Contact your administrator to change the package installation user interface option to Basic."

Unlike previous windows versions, where the uninstallation process would stop when encountering the custom exception message.

Is there any problem with the above override installer code?

Kindly help us to solve this issue.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,990 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,547 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,676 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. DR. PREMALATHA SATHIANARAYANAN 80 Reputation points
    2024-06-20T15:05:41.8266667+00:00

    The issue you are facing with uninstalling the MSI application on recent Windows updates seems to be related to how Windows Installer handles the uninstallation process, particularly with applications running in the background or encountering errors during uninstallation.

    Here are some steps and considerations to help solve this issue:

    Ensure Proper Uninstallation: Make sure that your MSI installer is correctly configured to handle uninstallation gracefully, including stopping any background processes associated with the application during uninstallation.

    Check for Errors and Logging: Review the MSI installer logs (msi*.log files typically found in %temp% directory) to identify any specific errors or issues encountered during uninstallation. Look for error codes or messages that could indicate why the uninstallation process is failing to remove associated files.

    Handle Background Processes: Ensure that your uninstallation process properly stops and removes any background processes or services that belong to the application being uninstalled. Background processes can sometimes prevent files from being removed or cause the uninstallation to fail.

    Update MSI Package: If possible, update your MSI package to address any issues identified through logs or testing. Ensure that all components and files associated with the application are correctly configured for uninstallation.

    Test on Clean Systems: Test the uninstallation process on a clean system or virtual machine to ensure that there are no conflicting applications or settings causing the uninstallation to fail.

    Consider Administrative Rights: Ensure that the uninstallation is performed with administrative rights, as certain operations may require elevated privileges to complete successfully.

    User Interface Options: The error message about "advertised application is unsafe" suggests that there might be issues with how the MSI package is configured regarding the user interface options during installation. Review the MSI package settings related to installation and uninstallation user interface options (UI Level, UILevel, etc.) to ensure they are configured correctly.

    Consult MSI Documentation: Refer to Microsoft's documentation on Windows Installer (MSI) for troubleshooting uninstallation issues and recommended best practices.

    0 comments No comments