diff --git a/MyComputerManager/Helpers/NamespaceHelper.cs b/MyComputerManager/Helpers/NamespaceHelper.cs index 851574d..f4b6c30 100644 --- a/MyComputerManager/Helpers/NamespaceHelper.cs +++ b/MyComputerManager/Helpers/NamespaceHelper.cs @@ -55,10 +55,27 @@ public static List GetItemsInternal(RegistryKey rootkey, bool dis return new List(); foreach (var item in LocalMachineNamespace.GetSubKeyNames()) { - var clsidkey = Registry.ClassesRoot.OpenSubKey(@"CLSID", false); + var clsidrootkey = Registry.CurrentUser; + var clsidkey = clsidrootkey.OpenSubKey(@"SOFTWARE\Classes\CLSID", false); var itemkey = clsidkey.OpenSubKey(item, false); - //var clsidkey = rootkey.OpenSubKey(@"SOFTWARE\Classes\CLSID", false); - //var itemkey = clsidkey.OpenSubKey(item, false); + if (itemkey == null) + { + clsidrootkey = Registry.LocalMachine; + clsidkey = clsidrootkey.OpenSubKey(@"SOFTWARE\Classes\CLSID", false); + itemkey = clsidkey.OpenSubKey(item, false); + } + if (itemkey == null) + { + clsidrootkey = Registry.CurrentUser; + clsidkey = clsidrootkey.OpenSubKey(@"SOFTWARE\Classes\WOW6432Node\CLSID", false); + itemkey = clsidkey.OpenSubKey(item, false); + } + if (itemkey == null) + { + clsidrootkey = Registry.LocalMachine; + clsidkey = clsidrootkey.OpenSubKey(@"SOFTWARE\Classes\WOW6432Node\CLSID", false); + itemkey = clsidkey.OpenSubKey(item, false); + } if (itemkey != null) { var iconkey = itemkey.OpenSubKey("DefaultIcon"); @@ -72,7 +89,7 @@ public static List GetItemsInternal(RegistryKey rootkey, bool dis string exepath = (string)(exekey?.GetValue("") ?? ""); if (name == "") continue; - list.Add(new NamespaceItem(name, desc, tip, exepath, iconpath, rootkey, disabled, item)); + list.Add(new NamespaceItem(name, desc, tip, exepath, iconpath, rootkey, clsidkey, disabled, item)); } } return list; @@ -88,7 +105,7 @@ public static CommonResult UpdateItem(NamespaceItem item) var namespaceSubKey = namespaceKey.CreateSubKey(item.CLSID, true); if (namespaceSubKey == null) return new CommonResult(false, "找不到Namespace下的" + item.CLSID); - var clsidKey = Registry.ClassesRoot.CreateSubKey(@"CLSID", true); + var clsidKey = item.RegKey1; if (clsidKey == null) return new CommonResult(false, "找不到CLSID key"); var clsidSubKey = clsidKey.CreateSubKey(item.CLSID, true); @@ -179,7 +196,7 @@ public static CommonResult DeleteItem(NamespaceItem item) return new CommonResult(false, "找不到Namespace key"); namespaceKey.DeleteSubKeyTree(item.CLSID, false); - var clsidKey = item.RegKey.OpenSubKey(@"SOFTWARE\Classes\CLSID", true); + var clsidKey = item.RegKey1; if (clsidKey == null) return new CommonResult(false, "找不到CLSID key"); clsidKey.DeleteSubKeyTree(item.CLSID, false); diff --git a/MyComputerManager/Models/NamespaceItem.cs b/MyComputerManager/Models/NamespaceItem.cs index ab89e92..afd230e 100644 --- a/MyComputerManager/Models/NamespaceItem.cs +++ b/MyComputerManager/Models/NamespaceItem.cs @@ -17,7 +17,7 @@ public NamespaceItem() { } - public NamespaceItem(string name, string desc, string tip, string exePath, string iconPath, RegistryKey key, bool disabled, string cLSID) + public NamespaceItem(string name, string desc, string tip, string exePath, string iconPath, RegistryKey key, RegistryKey key1, bool disabled, string cLSID) { Name = name; Desc = desc; @@ -25,6 +25,7 @@ public NamespaceItem(string name, string desc, string tip, string exePath, strin ExePath = exePath; IconPath = iconPath; RegKey = key; + RegKey1 = key1; isEnabled = !disabled; CLSID = cLSID; } @@ -33,6 +34,7 @@ public NamespaceItem(string name) { Name = name; RegKey = Registry.CurrentUser; + RegKey1 = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Classes\CLSID", true); isEnabled = true; CLSID = null; Desc = ""; @@ -133,6 +135,7 @@ public bool IsEnabled } public RegistryKey RegKey { get; set; } + public RegistryKey RegKey1 { get; set; } public string RegKey_Namespace { @@ -145,7 +148,7 @@ public string RegKey_CLSID { get { - return @"HKEY_CLASSES_ROOT\CLSID\" + CLSID; + return RegKey1.Name + @"\" + CLSID; } } @@ -159,6 +162,7 @@ public NamespaceItem Clone() Tip = Tip, IconPath = IconPath, RegKey = RegKey, + RegKey1 = RegKey1, IsEnabled = IsEnabled, Icon = Icon, ExePath = ExePath