/// <summary> /// Enumerates Shell extensions. /// </summary> /// <param name="registrationType">Type of the registration.</param> /// <param name="shellExtensionTypes">The shell extension types.</param> /// <returns></returns> public static IEnumerable<ShellExtensionRegistrationInfo> EnumerateExtensions(RegistrationType registrationType, ShellExtensionType shellExtensionTypes) { var shellExtensionsGuidMap = new Dictionary<Guid, ShellExtensionRegistrationInfo>(); // Go through all classes. using (var classes = OpenClassesRoot(registrationType)) { // Read each subkey. foreach (var className in classes.GetSubKeyNames().Where(cn => !cn.StartsWith("{"))) { // Go through every shell extension type. foreach (ShellExtensionType shellExtensionType in Enum.GetValues(typeof (ShellExtensionType))) { // Get the handler subkey. var handlerSubkey = shellExtensionType.GetAttribute<HandlerSubkeyAttribute>(); if(handlerSubkey == null) continue; // Check for the subkey. if (handlerSubkey.AllowMultipleEntries) { // Do we have the single subkey? var handlerKeyPath = string.Format("{0}\\shellex\\{1}", className, handlerSubkey.HandlerSubkey); using (var handlerSubKey = classes.OpenSubKey(handlerKeyPath, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey | RegistryRights.QueryValues)) { if (handlerSubKey != null) { // Read entries. foreach (var entry in handlerSubKey.GetSubKeyNames()) { using (var entryKey = handlerSubKey.OpenSubKey(entry, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.QueryValues | RegistryRights.ReadKey)) { var guidVal = entryKey.GetValue(null, string.Empty).ToString(); Guid guid; if (Guid.TryParse(guidVal, out guid) == false) continue; System.Diagnostics.Trace.WriteLine(string.Format("{0} has {3} {1} guid {2}", className, shellExtensionType.ToString(), guid, entry)); // If we do not have a shell extension info for this extension, create one. if (!shellExtensionsGuidMap.ContainsKey(guid)) { shellExtensionsGuidMap[guid] = new ShellExtensionRegistrationInfo { DisplayName = entry, ShellExtensionType = shellExtensionType, ServerCLSID = guid, }; } // Add the class association. shellExtensionsGuidMap[guid].classRegistrations.Add(new ClassRegistration(className)); } } } } } else { // Do we have the single subkey? var handlerKeyPath = string.Format("{0}\\shellex\\{1}", className, handlerSubkey.HandlerSubkey); using (var handlerSubKey = classes.OpenSubKey(handlerKeyPath, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey | RegistryRights.QueryValues)) { if (handlerSubKey != null) { var guidVal = handlerSubKey.GetValue(null, string.Empty).ToString(); Guid guid; if (Guid.TryParse(guidVal, out guid) == false) continue; System.Diagnostics.Trace.WriteLine(string.Format("{0} has {1} guid {2}", className, shellExtensionType.ToString(), guid)); // If we do not have a shell extension info for this extension, create one. if (!shellExtensionsGuidMap.ContainsKey(guid)) { shellExtensionsGuidMap[guid] = new ShellExtensionRegistrationInfo { ShellExtensionType = shellExtensionType, ServerCLSID = guid, }; } // Add the class association. shellExtensionsGuidMap[guid].classRegistrations.Add(new ClassRegistration(className)); } } } } } } return shellExtensionsGuidMap.Values; }
/// <summary> /// Enumerates Shell extensions. /// </summary> /// <param name="registrationType">Type of the registration.</param> /// <param name="shellExtensionTypes">The shell extension types.</param> /// <returns></returns> public static IEnumerable <ShellExtensionRegistrationInfo> EnumerateExtensions(RegistrationType registrationType, ShellExtensionType shellExtensionTypes) { var shellExtensionsGuidMap = new Dictionary <Guid, ShellExtensionRegistrationInfo>(); // Go through all classes. using (var classes = OpenClassesRoot(registrationType)) { // Read each subkey. foreach (var className in classes.GetSubKeyNames().Where(cn => !cn.StartsWith("{"))) { // Go through every shell extension type. foreach (ShellExtensionType shellExtensionType in Enum.GetValues(typeof(ShellExtensionType))) { // Get the handler subkey. var handlerSubkey = shellExtensionType.GetAttribute <HandlerSubkeyAttribute>(); if (handlerSubkey == null) { continue; } // Check for the subkey. if (handlerSubkey.AllowMultipleEntries) { // Do we have the single subkey? var handlerKeyPath = string.Format("{0}\\shellex\\{1}", className, handlerSubkey.HandlerSubkey); using (var handlerSubKey = classes.OpenSubKey(handlerKeyPath, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey | RegistryRights.QueryValues)) { if (handlerSubKey != null) { // Read entries. foreach (var entry in handlerSubKey.GetSubKeyNames()) { using (var entryKey = handlerSubKey.OpenSubKey(entry, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.QueryValues | RegistryRights.ReadKey)) { var guidVal = entryKey.GetValue(null, string.Empty).ToString(); Guid guid; if (Guid.TryParse(guidVal, out guid) == false) { continue; } System.Diagnostics.Trace.WriteLine(string.Format("{0} has {3} {1} guid {2}", className, shellExtensionType.ToString(), guid, entry)); // If we do not have a shell extension info for this extension, create one. if (!shellExtensionsGuidMap.ContainsKey(guid)) { shellExtensionsGuidMap[guid] = new ShellExtensionRegistrationInfo { DisplayName = entry, ShellExtensionType = shellExtensionType, ServerCLSID = guid, }; } // Add the class association. shellExtensionsGuidMap[guid].classRegistrations.Add(new ClassRegistration(className)); } } } } } else { // Do we have the single subkey? var handlerKeyPath = string.Format("{0}\\shellex\\{1}", className, handlerSubkey.HandlerSubkey); using (var handlerSubKey = classes.OpenSubKey(handlerKeyPath, RegistryKeyPermissionCheck.ReadSubTree, RegistryRights.ReadKey | RegistryRights.QueryValues)) { if (handlerSubKey != null) { var guidVal = handlerSubKey.GetValue(null, string.Empty).ToString(); Guid guid; if (Guid.TryParse(guidVal, out guid) == false) { continue; } System.Diagnostics.Trace.WriteLine(string.Format("{0} has {1} guid {2}", className, shellExtensionType.ToString(), guid)); // If we do not have a shell extension info for this extension, create one. if (!shellExtensionsGuidMap.ContainsKey(guid)) { shellExtensionsGuidMap[guid] = new ShellExtensionRegistrationInfo { ShellExtensionType = shellExtensionType, ServerCLSID = guid, }; } // Add the class association. shellExtensionsGuidMap[guid].classRegistrations.Add(new ClassRegistration(className)); } } } } } } return(shellExtensionsGuidMap.Values); }
/// <summary> /// Uninstalls the server. /// </summary> /// <param name="registrationInfo">The server's registration information.</param> /// <param name="registrationType">Type of the registration.</param> /// <returns>True if the server WAS installed and has been uninstalled, false if the server was not found.</returns> public static bool UninstallServer( ShellExtensionRegistrationInfo registrationInfo, RegistrationType registrationType) { return(UninstallServer(registrationInfo.ServerCLSID, registrationType)); }