diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1725265..1218d5a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ on: version: description: 'Build & package version' required: true - default: 0.0.14 + default: 0.1.0 type: string jobs: Build: diff --git a/MsiZapEx/BundleInfo.cs b/MsiZapEx/BundleInfo.cs index 0140c13..39b8c17 100644 --- a/MsiZapEx/BundleInfo.cs +++ b/MsiZapEx/BundleInfo.cs @@ -1,4 +1,4 @@ -using Microsoft.Win32; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.IO; @@ -9,7 +9,7 @@ namespace MsiZapEx public class BundleInfo { - // HKLM32 Software\Microsoft\Windows\CurrentVersion\Uninstall\ + // HKLM32/HKLM64 Software\Microsoft\Windows\CurrentVersion\Uninstall\ // HKCR HKEY_CLASSES_ROOT\Installer\Dependencies\\@ = // HKCR HKEY_CLASSES_ROOT\Installer\Dependencies\*\Dependents\ [Flags] @@ -25,6 +25,7 @@ public enum StatusFlags Good = ProviderKeyProductCodeMatch | HkcrDependencies | ArpPorviderKey | ArpUpgradeCodes | ARP } + public RegistryView RegistryView { get; private set; } public Guid BundleProductCode { get; private set; } = Guid.Empty; public List BundleUpgradeCodes { get; private set; } = new List(); public string BundleProviderKey { get; private set; } @@ -36,12 +37,20 @@ public enum StatusFlags public StatusFlags Status { get; private set; } = StatusFlags.None; public static List FindByUpgradeCode(Guid bundleUpgradeCode) + { + List bundles = new List(); + bundles.AddRange(FindByUpgradeCode(bundleUpgradeCode, RegistryView.Registry32)); + bundles.AddRange(FindByUpgradeCode(bundleUpgradeCode, RegistryView.Registry64)); + return bundles; + } + + private static List FindByUpgradeCode(Guid bundleUpgradeCode, RegistryView view) { List bundles = new List(); - using (RegistryKey hklm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) + using (RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, view)) { - using (RegistryKey hkUninstall = hklm32.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false)) + using (RegistryKey hkUninstall = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", false)) { if (hkUninstall == null) { @@ -75,7 +84,7 @@ public static List FindByUpgradeCode(Guid bundleUpgradeCode) case RegistryValueKind.String: if (Guid.TryParse(hkSubkey.GetValue("BundleUpgradeCode")?.ToString(), out Guid bug) && bug.Equals(bundleUpgradeCode)) { - BundleInfo bundle = new BundleInfo(bundleProductCode); + BundleInfo bundle = new BundleInfo(bundleProductCode, view); bundles.Add(bundle); } continue; @@ -83,7 +92,7 @@ public static List FindByUpgradeCode(Guid bundleUpgradeCode) case RegistryValueKind.MultiString: if ((hkSubkey.GetValue("BundleUpgradeCode") is IEnumerable bugs) && bugs.Any(uc => Guid.TryParse(uc, out Guid bug1) && bug1.Equals(bundleUpgradeCode))) { - BundleInfo bundle = new BundleInfo(bundleProductCode); + BundleInfo bundle = new BundleInfo(bundleProductCode, view); bundles.Add(bundle); } break; @@ -101,7 +110,7 @@ public void Prune() { if (!BundleProductCode.Equals(Guid.Empty)) { - modifier.DeferDeleteKey(RegistryHive.LocalMachine, RegistryView.Registry32, $@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{BundleProductCode.ToString("B")}"); + modifier.DeferDeleteKey(RegistryHive.LocalMachine, RegistryView, $@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{BundleProductCode.ToString("B")}"); foreach (string d in Dependents) { @@ -146,6 +155,7 @@ internal void PrintState() if (!BundleProductCode.Equals(Guid.Empty)) { Console.WriteLine($"\tBundleProductCode '{BundleProductCode}'"); + Console.WriteLine($"\tBitness '{RegistryView}'"); } if (!Status.HasFlag(StatusFlags.ArpUpgradeCodes)) @@ -194,9 +204,9 @@ internal void PrintState() } } - public BundleInfo(Guid bundleProductCode) + public BundleInfo(Guid bundleProductCode, RegistryView? view = null) { - ReadARP(bundleProductCode); + ReadARP(bundleProductCode, view); } private void ReadDependencies(string bundleProviderKey) @@ -219,10 +229,6 @@ private void ReadDependencies(string bundleProviderKey) if (Guid.TryParse(hkProviderKey.GetValue("")?.ToString(), out Guid bpc)) { - if (BundleProductCode.Equals(Guid.Empty)) - { - ReadARP(bpc); - } if (BundleProductCode.Equals(bpc)) { Status |= StatusFlags.ProviderKeyProductCodeMatch; @@ -262,18 +268,24 @@ private void ReadDependencies(string bundleProviderKey) } } - private void ReadARP(Guid bundleProductCode) + private void ReadARP(Guid bundleProductCode, RegistryView? view) { BundleProductCode = bundleProductCode; - using (RegistryKey hklm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) + RegistryView implicitView = view ?? RegistryView.Registry32; + using (RegistryKey hklm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, implicitView)) { using (RegistryKey hkUninstall = hklm32.OpenSubKey($@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{bundleProductCode.ToString("B")}", false)) { if (hkUninstall == null) { + if (view == null) + { + ReadARP(bundleProductCode, RegistryView.Registry64); + } return; } Status |= StatusFlags.ARP; + RegistryView = implicitView; RegistryValueKind valueKind = hkUninstall.GetValueKind("BundleUpgradeCode"); switch (valueKind)