public static ActionResult del_NSIS_DECAC(Session session) { // Leaves the Config /* * If NSIS is installed: * remove salt-minion service, * remove registry * remove files, except /salt/conf and /salt/var * * Instead of the above, TODO use uninst.exe and preserve the 2 directories (by moving them into safety first?) * This would be cleaner code * uninst /S does leave the installdir while uninst /s /DeleteInstallDir delete the installdir, both silentyl */ session.Log("...BEGIN del_NSIS_DECAC"); session.Log("...VERSION MinionConfigurationExtensionCA 1"); RegistryKey reg = Registry.LocalMachine; // ?When this is under SOFTWARE\WoW6432Node string Salt_uninstall_regpath64 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Salt Minion"; string Salt_uninstall_regpath32 = @"SOFTWARE\WoW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Salt Minion"; var SaltRegSubkey64 = reg.OpenSubKey(Salt_uninstall_regpath64); var SaltRegSubkey32 = reg.OpenSubKey(Salt_uninstall_regpath32); bool NSIS_is_installed64 = (SaltRegSubkey64 != null) && SaltRegSubkey64.GetValue("UninstallString").ToString().Equals(@"c:\salt\uninst.exe", StringComparison.OrdinalIgnoreCase); bool NSIS_is_installed32 = (SaltRegSubkey32 != null) && SaltRegSubkey32.GetValue("UninstallString").ToString().Equals(@"c:\salt\uninst.exe", StringComparison.OrdinalIgnoreCase); session.Log("delete_NSIS_files:: NSIS_is_installed64 = " + NSIS_is_installed64); session.Log("delete_NSIS_files:: NSIS_is_installed32 = " + NSIS_is_installed32); if (NSIS_is_installed64 || NSIS_is_installed32) { session.Log("delete_NSIS_files:: Going to stop service salt-minion ..."); MinionConfigurationUtilities.shellout(session, "sc stop salt-minion"); session.Log("delete_NSIS_files:: Going to delete service salt-minion ..."); MinionConfigurationUtilities.shellout(session, "sc delete salt-minion"); // shellout waits, but does sc? Does this work? session.Log("delete_NSIS_files:: Going to delete ARP registry64 entry for salt-minion ..."); try { reg.DeleteSubKeyTree(Salt_uninstall_regpath64); } catch (Exception ex) { MinionConfigurationUtilities.just_ExceptionLog("", session, ex); } session.Log("delete_NSIS_files:: Going to delete ARP registry32 entry for salt-minion ..."); try { reg.DeleteSubKeyTree(Salt_uninstall_regpath32); } catch (Exception ex) { MinionConfigurationUtilities.just_ExceptionLog("", session, ex); } session.Log("delete_NSIS_files:: Going to delete files ..."); try { Directory.Delete(@"c:\salt\bin", true); } catch (Exception ex) { MinionConfigurationUtilities.just_ExceptionLog("", session, ex); } try { File.Delete(@"c:\salt\uninst.exe"); } catch (Exception ex) { MinionConfigurationUtilities.just_ExceptionLog("", session, ex); } try { File.Delete(@"c:\salt\nssm.exe"); } catch (Exception ex) { MinionConfigurationUtilities.just_ExceptionLog("", session, ex); } try { foreach (FileInfo fi in new DirectoryInfo(@"c:\salt").GetFiles("salt*.*")) { fi.Delete(); } } catch (Exception) {; } } session.Log("...END del_NSIS_DECAC"); return(ActionResult.Success); }
private static void PurgeDir(Session session, string dir_below_salt_root) { String abs_dir = @"c:\salt\" + dir_below_salt_root; //TODO use root_dir String root_dir = ""; root_dir = session.CustomActionData["root_dir"]; if (Directory.Exists(abs_dir)) { session.Log("PurgeDir:: about to Directory.delete " + abs_dir); Directory.Delete(abs_dir, true); session.Log("PurgeDir:: ...OK"); } else { session.Log("PurgeDir:: no Directory " + abs_dir); } // quirk for https://github.com/markuskramerIgitt/salt-windows-msi/issues/33 Exception: Access to the path 'minion.pem' is denied . Read only! MinionConfigurationUtilities.shellout(session, @"rmdir /s /q " + abs_dir); }