private static void Unregister(Type registerType) { if (registerType != null && registerType.IsSubclassOf(typeof(PreviewHandler))) { object[] attrs = (object[])registerType.GetCustomAttributes(typeof(PreviewHandlerAttribute), true); if (attrs != null && attrs.Length == 1) { PreviewHandlerAttribute attr = attrs[0] as PreviewHandlerAttribute; UnregisterPreviewHandler(registerType.GUID, attr); } } }
private static void RegisterPreviewHandler(Guid previewerGuid, PreviewHandlerAttribute attribute) { var guid = previewerGuid.ToString("B"); // Create a new prevhost AppID so that this always runs in its own isolated process using (var appIdsKey = Registry.ClassesRoot.OpenSubKey("AppID", true)) using (var appIdKey = appIdsKey.CreateSubKey(attribute.AppId)) { appIdKey.SetValue("DllSurrogate", @"%SystemRoot%\system32\prevhost.exe", RegistryValueKind.ExpandString); } // Add preview handler to preview handler list using (var handlersKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PreviewHandlers", true)) { handlersKey.SetValue(guid, attribute.Name, RegistryValueKind.String); } // Modify preview handler registration using (var clsidKey = Registry.ClassesRoot.OpenSubKey("CLSID")) using (var idKey = clsidKey.OpenSubKey(guid, true)) { idKey.SetValue("DisplayName", attribute.Name, RegistryValueKind.String); idKey.SetValue("AppID", attribute.AppId, RegistryValueKind.String); idKey.SetValue("DisableLowILProcessIsolation", attribute.DisableLowILProcessIsolation ? 1 : 0, RegistryValueKind.DWord); using (var inproc = idKey.OpenSubKey("InprocServer32", true)) { inproc.SetValue("ThreadingModel", "Apartment", RegistryValueKind.String); } } foreach (var extension in attribute.Extensions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { Trace.WriteLine("Registering extension '" + extension + "' with previewer '" + guid + "'"); // Set preview handler for specific extension using (var extensionKey = Registry.ClassesRoot.CreateSubKey(extension)) using (var shellexKey = extensionKey.CreateSubKey("shellex")) using (var previewKey = shellexKey.CreateSubKey(Shell.Interop.HandlerNativeMethods.PreviewHandlerGuid.ToString("B"))) { previewKey.SetValue(null, guid, RegistryValueKind.String); } } }
private static void Register(Type registerType) { if (registerType != null && registerType.IsSubclassOf(typeof(PreviewHandler))) { object[] attrs = (object[])registerType.GetCustomAttributes(typeof(PreviewHandlerAttribute), true); if (attrs != null && attrs.Length == 1) { PreviewHandlerAttribute attr = attrs[0] as PreviewHandlerAttribute; ThrowIfNotValid(registerType); RegisterPreviewHandler(registerType.GUID, attr); } else { throw new NotSupportedException( string.Format(System.Globalization.CultureInfo.InvariantCulture, LocalizedMessages.PreviewHandlerInvalidAttributes, registerType.Name)); } } }
private static void UnregisterPreviewHandler(Guid previewerGuid, PreviewHandlerAttribute attribute) { var guid = previewerGuid.ToString("B"); foreach (var extension in attribute.Extensions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { Trace.WriteLine("Unregistering extension '" + extension + "' with previewer '" + guid + "'"); using (var shellexKey = Registry.ClassesRoot.OpenSubKey(extension + "\\shellex", true)) { shellexKey.DeleteSubKey(Shell.Interop.HandlerNativeMethods.PreviewHandlerGuid.ToString(), false); } } using (var appIdsKey = Registry.ClassesRoot.OpenSubKey("AppID", true)) { appIdsKey.DeleteSubKey(attribute.AppId, false); } using (var classesKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PreviewHandlers", true)) { classesKey.DeleteValue(guid, false); } }
private static void UnregisterPreviewHandler(Guid previewerGuid, PreviewHandlerAttribute attribute) { string guid = previewerGuid.ToString("B"); foreach (string extension in attribute.Extensions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { Trace.WriteLine("Unregistering extension '" + extension + "' with previewer '" + guid + "'"); using (RegistryKey shellexKey = Registry.ClassesRoot.OpenSubKey(extension + "\\shellex", true)) { shellexKey.DeleteSubKey(HandlerNativeMethods.IPreviewHandlerGuid.ToString(), false); } } using (RegistryKey appIdsKey = Registry.ClassesRoot.OpenSubKey("AppID", true)) { appIdsKey.DeleteSubKey(attribute.AppId, false); } using (RegistryKey classesKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PreviewHandlers", true)) { classesKey.DeleteValue(guid, false); } }
private static void RegisterPreviewHandler(Guid previewerGuid, PreviewHandlerAttribute attribute) { string guid = previewerGuid.ToString("B"); // Create a new prevhost AppID so that this always runs in its own isolated process using (RegistryKey appIdsKey = Registry.ClassesRoot.OpenSubKey("AppID", true)) using (RegistryKey appIdKey = appIdsKey.CreateSubKey(attribute.AppId)) { appIdKey.SetValue("DllSurrogate", @"%SystemRoot%\system32\prevhost.exe", RegistryValueKind.ExpandString); } // Add preview handler to preview handler list using (RegistryKey handlersKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\PreviewHandlers", true)) { handlersKey.SetValue(guid, attribute.Name, RegistryValueKind.String); } // Modify preview handler registration using (RegistryKey clsidKey = Registry.ClassesRoot.OpenSubKey("CLSID")) using (RegistryKey idKey = clsidKey.OpenSubKey(guid, true)) { idKey.SetValue("DisplayName", attribute.Name, RegistryValueKind.String); idKey.SetValue("AppID", attribute.AppId, RegistryValueKind.String); idKey.SetValue("DisableLowILProcessIsolation", attribute.DisableLowILProcessIsolation ? 1 : 0, RegistryValueKind.DWord); using (RegistryKey inproc = idKey.OpenSubKey("InprocServer32", true)) { inproc.SetValue("ThreadingModel", "Apartment", RegistryValueKind.String); } } foreach (string extension in attribute.Extensions.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { Trace.WriteLine("Registering extension '" + extension + "' with previewer '" + guid + "'"); // Set preview handler for specific extension using (RegistryKey extensionKey = Registry.ClassesRoot.CreateSubKey(extension)) using (RegistryKey shellexKey = extensionKey.CreateSubKey("shellex")) using (RegistryKey previewKey = shellexKey.CreateSubKey(HandlerNativeMethods.IPreviewHandlerGuid.ToString("B"))) { previewKey.SetValue(null, guid, RegistryValueKind.String); } } }