public Registry get_installer_keys(string packageId = null, string version = null, bool?nugetInstallable = null) { var snapshot = new Registry(); var windowsIdentity = WindowsIdentity.GetCurrent(); if (windowsIdentity != null) { snapshot.User = windowsIdentity.User.to_string(); } IList <RegistryKeyInfo> keys = new List <RegistryKeyInfo>(); if (Environment.Is64BitOperatingSystem) { add_key(keys, RegistryHive.CurrentUser, RegistryView.Registry64); add_key(keys, RegistryHive.LocalMachine, RegistryView.Registry64); } add_key(keys, RegistryHive.CurrentUser, RegistryView.Registry32); add_key(keys, RegistryHive.LocalMachine, RegistryView.Registry32); foreach (var regkey in keys) { var registryKey = regkey.key; var uninstallKey = FaultTolerance.try_catch_with_logging_exception( () => registryKey.OpenSubKey(UNINSTALLER_KEY_NAME, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey), "Could not open uninstall subkey for key '{0}'".format_with(registryKey.Name), logWarningInsteadOfError: true); if (uninstallKey != null) { //Console.WriteLine("Evaluating {0} of {1}".format_with(uninstallKey.View, uninstallKey.Name)); evaluate_keys(regkey, uninstallKey, snapshot, packageId, version, nugetInstallable); } registryKey.Close(); registryKey.Dispose(); } if (_logOutput) { Console.WriteLine(""); Console.WriteLine("A total of {0} unrecognized apps".format_with(snapshot.RegistryKeys.Where((p) => p.InstallerType == InstallerType.Unknown && p.is_in_programs_and_features()).Count())); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("A total of {0} of {1} are programs and features apps".format_with(snapshot.RegistryKeys.Where((p) => p.is_in_programs_and_features()).Count(), snapshot.RegistryKeys.Count)); Console.WriteLine(""); } return(snapshot); }
public Registry get_installer_keys() { var snapshot = new Registry(); var windowsIdentity = WindowsIdentity.GetCurrent(); if (windowsIdentity != null) { snapshot.User = windowsIdentity.User.to_string(); } IList <RegistryKey> keys = new List <RegistryKey>(); if (Environment.Is64BitOperatingSystem) { keys.Add(RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64)); keys.Add(RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)); } keys.Add(RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32)); keys.Add(RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)); foreach (var registryKey in keys) { var uninstallKey = registryKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey); if (uninstallKey != null) { //Console.WriteLine("Evaluating {0} of {1}".format_with(uninstallKey.View, uninstallKey.Name)); evaluate_keys(uninstallKey, snapshot); } registryKey.Close(); registryKey.Dispose(); } if (_logOutput) { Console.WriteLine(""); Console.WriteLine("A total of {0} unrecognized apps".format_with(snapshot.RegistryKeys.Where((p) => p.InstallerType == InstallerType.Unknown && p.is_in_programs_and_features()).Count())); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("A total of {0} of {1} are programs and features apps".format_with(snapshot.RegistryKeys.Where((p) => p.is_in_programs_and_features()).Count(), snapshot.RegistryKeys.Count)); Console.WriteLine(""); } return(snapshot); }
public Registry get_installer_keys() { var snapshot = new Registry(); var windowsIdentity = WindowsIdentity.GetCurrent(); if (windowsIdentity != null) snapshot.User = windowsIdentity.User.to_string(); IList<RegistryKey> keys = new List<RegistryKey>(); if (Environment.Is64BitOperatingSystem) { add_key(keys, RegistryHive.CurrentUser, RegistryView.Registry64); add_key(keys, RegistryHive.LocalMachine, RegistryView.Registry64); } add_key(keys, RegistryHive.CurrentUser, RegistryView.Registry32); add_key(keys, RegistryHive.LocalMachine, RegistryView.Registry32); foreach (var registryKey in keys) { var uninstallKey = FaultTolerance.try_catch_with_logging_exception( () => registryKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey), "Could not open uninstall subkey for key '{0}'".format_with(registryKey.Name), logWarningInsteadOfError: true); if (uninstallKey != null) { //Console.WriteLine("Evaluating {0} of {1}".format_with(uninstallKey.View, uninstallKey.Name)); evaluate_keys(uninstallKey, snapshot); } registryKey.Close(); registryKey.Dispose(); } if (_logOutput) { Console.WriteLine(""); Console.WriteLine("A total of {0} unrecognized apps".format_with(snapshot.RegistryKeys.Where((p) => p.InstallerType == InstallerType.Unknown && p.is_in_programs_and_features()).Count())); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("A total of {0} of {1} are programs and features apps".format_with(snapshot.RegistryKeys.Where((p) => p.is_in_programs_and_features()).Count(), snapshot.RegistryKeys.Count)); Console.WriteLine(""); } return snapshot; }
public void save_to_file(Registry snapshot, string filePath) { _xmlService.serialize(snapshot, filePath); }
public Registry get_differences(Registry before, Registry after) { //var difference = after.RegistryKeys.Where(r => !before.RegistryKeys.Contains(r)).ToList(); return(new Registry(after.User, after.RegistryKeys.Except(before.RegistryKeys).ToList())); }
/// <summary> /// Evaluates registry keys and updates the snapshop with items /// </summary> /// <param name="key">The key.</param> /// <param name="snapshot">The snapshot.</param> public void evaluate_keys(RegistryKey key, Registry snapshot) { if (key == null) { return; } FaultTolerance.try_catch_with_logging_exception( () => { foreach (var subKeyName in key.GetSubKeyNames()) { FaultTolerance.try_catch_with_logging_exception( () => evaluate_keys(key.OpenSubKey(subKeyName, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey), snapshot), "Failed to open subkey named '{0}' for '{1}', likely due to permissions".format_with(subKeyName, key.Name), logWarningInsteadOfError: true); } }, "Failed to open subkeys for '{0}', likely due to permissions".format_with(key.Name), logWarningInsteadOfError: true); var appKey = new RegistryApplicationKey { KeyPath = key.Name, RegistryView = key.View, DefaultValue = key.GetValue("").to_string(), DisplayName = key.GetValue("DisplayName").to_string() }; if (string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.DisplayName = appKey.DefaultValue; } if (!string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.InstallLocation = key.GetValue("InstallLocation").to_string(); appKey.UninstallString = key.GetValue("UninstallString").to_string(); if (key.GetValue("QuietUninstallString") != null) { appKey.UninstallString = key.GetValue("QuietUninstallString").to_string(); appKey.HasQuietUninstall = true; } // informational appKey.Publisher = key.GetValue("Publisher").to_string(); appKey.InstallDate = key.GetValue("InstallDate").to_string(); appKey.InstallSource = key.GetValue("InstallSource").to_string(); appKey.Language = key.GetValue("Language").to_string(); // Version appKey.DisplayVersion = key.GetValue("DisplayVersion").to_string(); appKey.Version = key.GetValue("Version").to_string(); appKey.VersionMajor = key.GetValue("VersionMajor").to_string(); appKey.VersionMinor = key.GetValue("VersionMinor").to_string(); // installinformation appKey.SystemComponent = key.GetValue("SystemComponent").to_string() == "1"; appKey.WindowsInstaller = key.GetValue("WindowsInstaller").to_string() == "1"; appKey.NoRemove = key.GetValue("NoRemove").to_string() == "1"; appKey.NoModify = key.GetValue("NoModify").to_string() == "1"; appKey.NoRepair = key.GetValue("NoRepair").to_string() == "1"; appKey.ReleaseType = key.GetValue("ReleaseType").to_string(); appKey.ParentKeyName = key.GetValue("ParentKeyName").to_string(); if (appKey.WindowsInstaller || appKey.UninstallString.to_lower().Contains("msiexec")) { appKey.InstallerType = InstallerType.Msi; } if (key.Name.EndsWith("_is1") || !string.IsNullOrWhiteSpace(key.GetValue("Inno Setup: Setup Version").to_string())) { appKey.InstallerType = InstallerType.InnoSetup; } if (key.GetValue("dwVersionMajor") != null) { appKey.InstallerType = InstallerType.Nsis; appKey.VersionMajor = key.GetValue("dwVersionMajor").to_string(); appKey.VersionMinor = key.GetValue("dwVersionMinor").to_string(); appKey.VersionRevision = key.GetValue("dwVersionRev").to_string(); appKey.VersionBuild = key.GetValue("dwVersionBuild").to_string(); } if (appKey.ReleaseType.is_equal_to("Hotfix") || appKey.ReleaseType.is_equal_to("Update Rollup") || appKey.ReleaseType.is_equal_to("Security Update") || appKey.DefaultValue.to_string().StartsWith("KB", ignoreCase: true, culture: CultureInfo.InvariantCulture)) { appKey.InstallerType = InstallerType.HotfixOrSecurityUpdate; } if (appKey.ReleaseType.is_equal_to("ServicePack")) { appKey.InstallerType = InstallerType.ServicePack; } // assume NSIS if we still don't know and we find uninst.exe if (appKey.InstallerType == InstallerType.Unknown && appKey.UninstallString.to_lower().Contains("uninst.exe")) { appKey.InstallerType = InstallerType.Nsis; } if (appKey.InstallerType == InstallerType.Unknown && appKey.HasQuietUninstall) { appKey.InstallerType = InstallerType.Custom; } if (_logOutput) { if (appKey.is_in_programs_and_features() && appKey.InstallerType == InstallerType.Unknown) { foreach (var name in key.GetValueNames()) { //var kind = key.GetValueKind(name); var value = key.GetValue(name); if (name.is_equal_to("QuietUninstallString") || name.is_equal_to("UninstallString")) { Console.WriteLine("key - {0}|{1}={2}|Type detected={3}".format_with(key.Name, name, value.to_string(), appKey.InstallerType.to_string())); } //Console.WriteLine("key - {0}, name - {1}, kind - {2}, value - {3}".format_with(key.Name, name, kind, value.to_string())); } } } snapshot.RegistryKeys.Add(appKey); } key.Close(); key.Dispose(); }
public Registry get_installer_key_differences(Registry before, Registry after) { //var difference = after.RegistryKeys.Where(r => !before.RegistryKeys.Contains(r)).ToList(); return new Registry(after.User, after.RegistryKeys.Except(before.RegistryKeys).ToList()); }
/// <summary> /// Evaluates registry keys and updates the snapshop with items /// </summary> /// <param name="key">The key.</param> /// <param name="snapshot">The snapshot.</param> public void evaluate_keys(RegistryKey key, Registry snapshot) { if (key == null) return; FaultTolerance.try_catch_with_logging_exception( () => { foreach (var subKeyName in key.GetSubKeyNames()) { FaultTolerance.try_catch_with_logging_exception( () => evaluate_keys(key.OpenSubKey(subKeyName, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey), snapshot), "Failed to open subkey named '{0}' for '{1}', likely due to permissions".format_with(subKeyName, key.Name), logWarningInsteadOfError: true); } }, "Failed to open subkeys for '{0}', likely due to permissions".format_with(key.Name), logWarningInsteadOfError: true); var appKey = new RegistryApplicationKey { KeyPath = key.Name, RegistryView = key.View, DefaultValue = key.get_value_as_string(""), DisplayName = key.get_value_as_string("DisplayName") }; if (string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.DisplayName = appKey.DefaultValue; } if (!string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.InstallLocation = key.get_value_as_string("InstallLocation"); appKey.UninstallString = key.get_value_as_string("UninstallString"); if (!string.IsNullOrWhiteSpace(key.get_value_as_string("QuietUninstallString"))) { appKey.UninstallString = key.get_value_as_string("QuietUninstallString"); appKey.HasQuietUninstall = true; } // informational appKey.Publisher = key.get_value_as_string("Publisher"); appKey.InstallDate = key.get_value_as_string("InstallDate"); appKey.InstallSource = key.get_value_as_string("InstallSource"); appKey.Language = key.get_value_as_string("Language"); // Version appKey.DisplayVersion = key.get_value_as_string("DisplayVersion"); appKey.Version = key.get_value_as_string("Version"); appKey.VersionMajor = key.get_value_as_string("VersionMajor"); appKey.VersionMinor = key.get_value_as_string("VersionMinor"); // installinformation appKey.SystemComponent = key.get_value_as_string("SystemComponent") == "1"; appKey.WindowsInstaller = key.get_value_as_string("WindowsInstaller") == "1"; appKey.NoRemove = key.get_value_as_string("NoRemove") == "1"; appKey.NoModify = key.get_value_as_string("NoModify") == "1"; appKey.NoRepair = key.get_value_as_string("NoRepair") == "1"; appKey.ReleaseType = key.get_value_as_string("ReleaseType"); appKey.ParentKeyName = key.get_value_as_string("ParentKeyName"); if (appKey.WindowsInstaller || appKey.UninstallString.to_string().to_lower().Contains("msiexec")) { appKey.InstallerType = InstallerType.Msi; } if (key.Name.EndsWith("_is1") || !string.IsNullOrWhiteSpace(key.get_value_as_string("Inno Setup: Setup Version"))) { appKey.InstallerType = InstallerType.InnoSetup; } if (!string.IsNullOrWhiteSpace(key.get_value_as_string("dwVersionMajor"))) { appKey.InstallerType = InstallerType.Nsis; appKey.VersionMajor = key.get_value_as_string("dwVersionMajor"); appKey.VersionMinor = key.get_value_as_string("dwVersionMinor"); appKey.VersionRevision = key.get_value_as_string("dwVersionRev"); appKey.VersionBuild = key.get_value_as_string("dwVersionBuild"); } if (appKey.ReleaseType.is_equal_to("Hotfix") || appKey.ReleaseType.is_equal_to("Update Rollup") || appKey.ReleaseType.is_equal_to("Security Update") || appKey.DefaultValue.to_string().StartsWith("KB", ignoreCase: true, culture: CultureInfo.InvariantCulture)) { appKey.InstallerType = InstallerType.HotfixOrSecurityUpdate; } if (appKey.ReleaseType.is_equal_to("ServicePack")) { appKey.InstallerType = InstallerType.ServicePack; } // assume NSIS if we still don't know and we find uninst.exe if (appKey.InstallerType == InstallerType.Unknown && appKey.UninstallString.to_string().to_lower().Contains("uninst.exe")) { appKey.InstallerType = InstallerType.Nsis; } if (appKey.InstallerType == InstallerType.Unknown && appKey.HasQuietUninstall) { appKey.InstallerType = InstallerType.Custom; } if (appKey.InstallerType == InstallerType.Msi) { get_msi_information(appKey, key); } if (_logOutput) { //if (appKey.is_in_programs_and_features() && appKey.InstallerType == InstallerType.Unknown) //{ foreach (var name in key.GetValueNames()) { //var kind = key.GetValueKind(name); var value = key.get_value_as_string(name); if (name.is_equal_to("QuietUninstallString") || name.is_equal_to("UninstallString")) { Console.WriteLine("key - {0}|{1}={2}|Type detected={3}|install location={4}".format_with(key.Name, name, value.to_string(), appKey.InstallerType.to_string(),appKey.InstallLocation.to_string())); } //Console.WriteLine("key - {0}, name - {1}, kind - {2}, value - {3}".format_with(key.Name, name, kind, value.to_string())); } //} } snapshot.RegistryKeys.Add(appKey); } key.Close(); key.Dispose(); }
/// <summary> /// Evaluates registry keys and updates the snapshop with items /// </summary> /// <param name="key">The key.</param> /// <param name="snapshot">The snapshot.</param> public void evaluate_keys(RegistryKey key, Registry snapshot) { foreach (var subKeyName in key.GetSubKeyNames()) { evaluate_keys(key.OpenSubKey(subKeyName), snapshot); } var appKey = new RegistryApplicationKey { KeyPath = key.Name, RegistryView = key.View, DefaultValue = key.GetValue("").to_string(), DisplayName = key.GetValue("DisplayName").to_string() }; if (string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.DisplayName = appKey.DefaultValue; } if (!string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.InstallLocation = key.GetValue("InstallLocation").to_string(); appKey.UninstallString = key.GetValue("UninstallString").to_string(); if (key.GetValue("QuietUninstallString") != null) { appKey.UninstallString = key.GetValue("QuietUninstallString").to_string(); appKey.HasQuietUninstall = true; } // informational appKey.Publisher = key.GetValue("Publisher").to_string(); appKey.InstallDate = key.GetValue("InstallDate").to_string(); appKey.InstallSource = key.GetValue("InstallSource").to_string(); appKey.Language = key.GetValue("Language").to_string(); // Version appKey.DisplayVersion = key.GetValue("DisplayVersion").to_string(); appKey.Version = key.GetValue("Version").to_string(); appKey.VersionMajor = key.GetValue("VersionMajor").to_string(); appKey.VersionMinor = key.GetValue("VersionMinor").to_string(); // installinformation appKey.SystemComponent = key.GetValue("SystemComponent").to_string() == "1"; appKey.WindowsInstaller = key.GetValue("WindowsInstaller").to_string() == "1"; appKey.NoRemove = key.GetValue("NoRemove").to_string() == "1"; appKey.NoModify = key.GetValue("NoModify").to_string() == "1"; appKey.NoRepair = key.GetValue("NoRepair").to_string() == "1"; appKey.ReleaseType = key.GetValue("ReleaseType").to_string(); appKey.ParentKeyName = key.GetValue("ParentKeyName").to_string(); if (appKey.WindowsInstaller || appKey.UninstallString.to_lower().Contains("msiexec")) { appKey.InstallerType = InstallerType.Msi; } if (key.Name.EndsWith("_is1") || !string.IsNullOrWhiteSpace(key.GetValue("Inno Setup: Setup Version").to_string())) { appKey.InstallerType = InstallerType.InnoSetup; } if (key.GetValue("dwVersionMajor") != null) { appKey.InstallerType = InstallerType.Nsis; appKey.VersionMajor = key.GetValue("dwVersionMajor").to_string(); appKey.VersionMinor = key.GetValue("dwVersionMinor").to_string(); appKey.VersionRevision = key.GetValue("dwVersionRev").to_string(); appKey.VersionBuild = key.GetValue("dwVersionBuild").to_string(); } if (appKey.ReleaseType.is_equal_to("Hotfix") || appKey.ReleaseType.is_equal_to("Update Rollup") || appKey.ReleaseType.is_equal_to("Security Update") || appKey.DefaultValue.to_string().StartsWith("KB", ignoreCase: true, culture: CultureInfo.InvariantCulture)) { appKey.InstallerType = InstallerType.HotfixOrSecurityUpdate; } if (appKey.ReleaseType.is_equal_to("ServicePack")) { appKey.InstallerType = InstallerType.ServicePack; } if (appKey.InstallerType == InstallerType.Unknown && appKey.HasQuietUninstall) { appKey.InstallerType = InstallerType.Custom; } //if (appKey.InstallerType == InstallerType.Msi) //{ //Console.WriteLine(""); //if (!string.IsNullOrWhiteSpace(appKey.UninstallString)) //{ // Console.WriteLine(appKey.UninstallString.to_string().Split(new[] { " /", " -" }, StringSplitOptions.RemoveEmptyEntries)[0]); // key.UninstallString.to_string().Split(new[] { " /", " -" }, StringSplitOptions.RemoveEmptyEntries); //} //foreach (var name in key.GetValueNames()) //{ // var kind = key.GetValueKind(name); // var value = key.GetValue(name); // Console.WriteLine("key - {0}, name - {1}, kind - {2}, value - {3}".format_with(key.Name, name, kind, value.to_string())); //} //} snapshot.RegistryKeys.Add(appKey); } key.Close(); key.Dispose(); }
/// <summary> /// Evaluates registry keys and updates the snapshop with items /// </summary> /// <param name="key">The key.</param> /// <param name="snapshot">The snapshot.</param> public void evaluate_keys(RegistryKeyInfo regkey, RegistryKey key, Registry snapshot, string packageId = null, string version = null, bool?nugetInstallable = null) { if (key == null) { return; } FaultTolerance.try_catch_with_logging_exception( () => { Regex reMatchFile = null; if (packageId != null) { reMatchFile = FindFilesPatternToRegex.Convert(packageId); } foreach (var subKeyName in key.GetSubKeyNames()) { if (reMatchFile != null && !reMatchFile.IsMatch(subKeyName)) { continue; } regkey.SubKeyName = subKeyName; FaultTolerance.try_catch_with_logging_exception( () => evaluate_keys(regkey, key.OpenSubKey(subKeyName, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey), snapshot, packageId, version, nugetInstallable), "Failed to open subkey named '{0}' for '{1}', likely due to permissions".format_with(subKeyName, key.Name), logWarningInsteadOfError: true); } }, "Failed to open subkeys for '{0}', likely due to permissions".format_with(key.Name), logWarningInsteadOfError: true); var appKey = new RegistryApplicationKey { Hive = regkey.hive, KeyPath = key.Name, RegistryView = key.View, DefaultValue = key.get_value_as_string(""), DisplayName = key.get_value_as_string("DisplayName") }; if (string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.DisplayName = appKey.DefaultValue; } bool addRegEntry = false; if (!string.IsNullOrWhiteSpace(appKey.DisplayName)) { addRegEntry = true; appKey.PackageId = key.get_value_as_string("PackageId"); if (string.IsNullOrWhiteSpace(appKey.PackageId)) { appKey.PackageId = regkey.SubKeyName; } string s = key.get_value_as_string(nameof(RegistryApplicationKey.IsPinned)); if (string.IsNullOrWhiteSpace(s)) { appKey.IsPinned = false; } else { appKey.IsPinned = s != "0"; } appKey.InstallLocation = key.get_value_as_string("InstallLocation"); if (nugetInstallable.HasValue) { string dir = appKey.InstallLocation; bool isNugetInstallable = false; if (!String.IsNullOrEmpty(dir)) { string parentDir = System.IO.Path.GetDirectoryName(dir); string parentDirName = System.IO.Path.GetFileName(dir); if (parentDirName == appKey.PackageId) { string nuspecPath = System.IO.Path.Combine(dir, appKey.PackageId + NuGet.Constants.ManifestExtension); isNugetInstallable = System.IO.File.Exists(nuspecPath); } } if (nugetInstallable.Value != isNugetInstallable) { addRegEntry = false; } } } if (addRegEntry) { appKey.UninstallString = key.get_value_as_string("UninstallString"); if (!string.IsNullOrWhiteSpace(key.get_value_as_string("QuietUninstallString"))) { appKey.UninstallString = key.get_value_as_string("QuietUninstallString"); appKey.HasQuietUninstall = true; } // informational appKey.Publisher = key.get_value_as_string("Publisher"); appKey.InstallDate = key.get_value_as_string("InstallDate"); appKey.InstallSource = key.get_value_as_string("InstallSource"); appKey.Language = key.get_value_as_string("Language"); // Version appKey.DisplayVersion = key.get_value_as_string("DisplayVersion"); appKey.Version = key.get_value_as_string("Version"); appKey.VersionMajor = key.get_value_as_string("VersionMajor"); appKey.VersionMinor = key.get_value_as_string("VersionMinor"); // installinformation appKey.SystemComponent = key.get_value_as_string("SystemComponent") == "1"; appKey.WindowsInstaller = key.get_value_as_string("WindowsInstaller") == "1"; appKey.NoRemove = key.get_value_as_string("NoRemove") == "1"; appKey.NoModify = key.get_value_as_string("NoModify") == "1"; appKey.NoRepair = key.get_value_as_string("NoRepair") == "1"; appKey.ReleaseType = key.get_value_as_string("ReleaseType"); appKey.ParentKeyName = key.get_value_as_string("ParentKeyName"); appKey.DisplayIcon = key.get_value_as_string("DisplayIcon"); long size = 0; if (long.TryParse(key.get_value_as_string("EstimatedSize"), out size)) { appKey.EstimatedSize = size; } if (appKey.WindowsInstaller || appKey.UninstallString.to_string().to_lower().Contains("msiexec")) { appKey.InstallerType = InstallerType.Msi; } if (key.Name.EndsWith("_is1") || !string.IsNullOrWhiteSpace(key.get_value_as_string("Inno Setup: Setup Version"))) { appKey.InstallerType = InstallerType.InnoSetup; } if (!string.IsNullOrWhiteSpace(key.get_value_as_string("dwVersionMajor"))) { appKey.InstallerType = InstallerType.Nsis; appKey.VersionMajor = key.get_value_as_string("dwVersionMajor"); appKey.VersionMinor = key.get_value_as_string("dwVersionMinor"); appKey.VersionRevision = key.get_value_as_string("dwVersionRev"); appKey.VersionBuild = key.get_value_as_string("dwVersionBuild"); } if (appKey.ReleaseType.is_equal_to("Hotfix") || appKey.ReleaseType.is_equal_to("Update Rollup") || appKey.ReleaseType.is_equal_to("Security Update") || appKey.DefaultValue.to_string().StartsWith("KB", ignoreCase: true, culture: CultureInfo.InvariantCulture)) { appKey.InstallerType = InstallerType.HotfixOrSecurityUpdate; } if (appKey.ReleaseType.is_equal_to("ServicePack")) { appKey.InstallerType = InstallerType.ServicePack; } // assume NSIS if we still don't know and we find uninst.exe if (appKey.InstallerType == InstallerType.Unknown && appKey.UninstallString.to_string().to_lower().Contains("uninst.exe")) { appKey.InstallerType = InstallerType.Nsis; } if (appKey.InstallerType == InstallerType.Unknown && appKey.HasQuietUninstall) { appKey.InstallerType = InstallerType.Custom; } if (appKey.InstallerType == InstallerType.Msi) { get_msi_information(appKey, key); } if (_logOutput) { //if (appKey.is_in_programs_and_features() && appKey.InstallerType == InstallerType.Unknown) //{ foreach (var name in key.GetValueNames()) { //var kind = key.GetValueKind(name); var value = key.get_value_as_string(name); if (name.is_equal_to("QuietUninstallString") || name.is_equal_to("UninstallString")) { Console.WriteLine("key - {0}|{1}={2}|Type detected={3}|install location={4}".format_with(key.Name, name, value.to_string(), appKey.InstallerType.to_string(), appKey.InstallLocation.to_string())); } //Console.WriteLine("key - {0}, name - {1}, kind - {2}, value - {3}".format_with(key.Name, name, kind, value.to_string())); } //} } snapshot.RegistryKeys.Add(appKey); } key.Close(); key.Dispose(); }
/// <summary> /// Evaluates registry keys and updates the snapshop with items /// </summary> /// <param name="key">The key.</param> /// <param name="snapshot">The snapshot.</param> public void evaluate_keys(RegistryKey key, Registry snapshot) { foreach (var subKeyName in key.GetSubKeyNames()) { evaluate_keys(key.OpenSubKey(subKeyName), snapshot); } var appKey = new RegistryApplicationKey { KeyPath = key.Name, RegistryView = key.View, DefaultValue = key.GetValue("").to_string(), DisplayName = key.GetValue("DisplayName").to_string() }; if (string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.DisplayName = appKey.DefaultValue; } if (!string.IsNullOrWhiteSpace(appKey.DisplayName)) { appKey.InstallLocation = key.GetValue("InstallLocation").to_string(); appKey.UninstallString = key.GetValue("UninstallString").to_string(); if (key.GetValue("QuietUninstallString") != null) { appKey.UninstallString = key.GetValue("QuietUninstallString").to_string(); appKey.HasQuietUninstall = true; } // informational appKey.Publisher = key.GetValue("Publisher").to_string(); appKey.InstallDate = key.GetValue("InstallDate").to_string(); appKey.InstallSource = key.GetValue("InstallSource").to_string(); appKey.Language = key.GetValue("Language").to_string(); // Version appKey.DisplayVersion = key.GetValue("DisplayVersion").to_string(); appKey.Version = key.GetValue("Version").to_string(); appKey.VersionMajor = key.GetValue("VersionMajor").to_string(); appKey.VersionMinor = key.GetValue("VersionMinor").to_string(); // installinformation appKey.SystemComponent = key.GetValue("SystemComponent").to_string() == "1"; appKey.WindowsInstaller = key.GetValue("WindowsInstaller").to_string() == "1"; appKey.NoRemove = key.GetValue("NoRemove").to_string() == "1"; appKey.NoModify = key.GetValue("NoModify").to_string() == "1"; appKey.NoRepair = key.GetValue("NoRepair").to_string() == "1"; appKey.ReleaseType = key.GetValue("ReleaseType").to_string(); appKey.ParentKeyName = key.GetValue("ParentKeyName").to_string(); if (appKey.WindowsInstaller || appKey.UninstallString.to_lower().Contains("msiexec")) { appKey.InstallerType = InstallerType.Msi; } if (key.Name.EndsWith("_is1") || !string.IsNullOrWhiteSpace(key.GetValue("Inno Setup: Setup Version").to_string())) { appKey.InstallerType = InstallerType.InnoSetup; } if (key.GetValue("dwVersionMajor") != null) { appKey.InstallerType = InstallerType.Nsis; appKey.VersionMajor = key.GetValue("dwVersionMajor").to_string(); appKey.VersionMinor = key.GetValue("dwVersionMinor").to_string(); appKey.VersionRevision = key.GetValue("dwVersionRev").to_string(); appKey.VersionBuild = key.GetValue("dwVersionBuild").to_string(); } if (appKey.ReleaseType.is_equal_to("Hotfix") || appKey.ReleaseType.is_equal_to("Update Rollup") || appKey.ReleaseType.is_equal_to("Security Update") || appKey.DefaultValue.to_string().StartsWith("KB", ignoreCase: true, culture: CultureInfo.InvariantCulture)) { appKey.InstallerType = InstallerType.HotfixOrSecurityUpdate; } if (appKey.ReleaseType.is_equal_to("ServicePack")) { appKey.InstallerType = InstallerType.ServicePack; } if (appKey.InstallerType == InstallerType.Unknown && appKey.HasQuietUninstall) { appKey.InstallerType = InstallerType.Custom; } if (_logOutput) { if (appKey.is_in_programs_and_features() && appKey.InstallerType == InstallerType.Unknown) { foreach (var name in key.GetValueNames()) { //var kind = key.GetValueKind(name); var value = key.GetValue(name); if (name.is_equal_to("QuietUninstallString") || name.is_equal_to("UninstallString")) { Console.WriteLine("key - {0}|{1}={2}|Type detected={3}".format_with(key.Name, name, value.to_string(), appKey.InstallerType.to_string())); } //Console.WriteLine("key - {0}, name - {1}, kind - {2}, value - {3}".format_with(key.Name, name, kind, value.to_string())); } } } snapshot.RegistryKeys.Add(appKey); } key.Close(); key.Dispose(); }