SDA-4562 (Uninstall nsis installer registry entries) (#2151)

* SDA-4562 - Uninstall nsis installation if exists

* SDA-4562 - Fix script issue

* SDA-4562 - Fix script issue

* SDA-4562 - Use QuietUninstallString and wait for exit

* SDA-4562 - Change custom action execute settings

* SDA-4562 - Change custom action execute settings

* SDA-4562 - Change custom action execute settings

* SDA-4562 - Use command instead of shellExecute

* SDA-4562 - Use command instead of shellExecute
This commit is contained in:
Kiran Niranjan 2024-05-24 13:30:28 +05:30 committed by GitHub
parent 47bbaf9a13
commit 0e7e3b9d64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -170,6 +170,15 @@ class Script
// Define the custom actions we want to run, and at what point of the installation we want to execute them. // Define the custom actions we want to run, and at what point of the installation we want to execute them.
project.Actions = new WixSharp.Action[] project.Actions = new WixSharp.Action[]
{ {
// CleanNSISRegistryForCurrentUser
//
// This custom action is to remove any registry entries from HKEY_CURRENT_USER if exists
new ManagedAction(CustomActions.CleanNSISRegistryForCurrentUser, Return.check, When.Before, Step.LaunchConditions, Condition.NOT_Installed )
{
UsesProperties = "INSTALLDIR"
},
// InstallVariant // InstallVariant
// //
// We want to be able to display the POD URL dialog every time SDA starts after a reinstall, regardless of // We want to be able to display the POD URL dialog every time SDA starts after a reinstall, regardless of
@ -518,6 +527,67 @@ public class CustomActions
return ActionResult.Success; return ActionResult.Success;
} }
// CleanNSISRegistryForCurrentUser custom action
[CustomAction]
public static ActionResult CleanNSISRegistryForCurrentUser(Session session)
{
// Check if the INSTALLDIR starts with the per user installation path
if (session["INSTALLDIR"].StartsWith(System.Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Programs\")))
{
try
{
const string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
const string displayNameValue = "Symphony";
// Open the Uninstall key
using (var key = Registry.CurrentUser.OpenSubKey(uninstallKey))
{
if (key == null)
{
session.Log("Uninstall key not found.");
return ActionResult.Success;
}
// Iterate through all subkeys
foreach (string subkeyName in key.GetSubKeyNames())
{
using (var subkey = key.OpenSubKey(subkeyName))
{
if (subkey == null)
{
continue;
}
// Get the DisplayName value
string displayName = subkey.GetValue("DisplayName") as string;
if (displayName == displayNameValue)
{
// Get the UninstallString value
string uninstallString = subkey.GetValue("QuietUninstallString") as string;
if (!string.IsNullOrEmpty(uninstallString))
{
// Start the uninstallation process
var process = new System.Diagnostics.Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = string.Format("/c \"{0}\"", uninstallString);
process.StartInfo.UseShellExecute = false;
process.Start();
process.WaitForExit();
}
}
}
}
}
}
catch (System.Exception e)
{
session.Log("Error executing CleanNSISRegistryForCurrentUser: " + e.ToString());
return ActionResult.Success;
}
}
return ActionResult.Success;
}
// StartAfterInstall custom action // StartAfterInstall custom action
[CustomAction] [CustomAction]
public static ActionResult StartAfterInstall(Session session) public static ActionResult StartAfterInstall(Session session)