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