Beispiel #1
0
        /// <summary>
        /// Adds additional info to the registry to allow the shell to discover the oject as shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        protected static void ComRegister(Type type, string description)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }

            // Only register when supported by Shell.
            // Vista and up don't support column providers anymore (replaces by property system).
            if (IsShell60OrHigher())
            {
                return;
            }

            RegistryExtensions.AddAsApprovedShellExtension(type, description);

            // Register the COM object as a ColumnProvider handler.
            var subKeyName = ColumnHandlersKeyName + @"\" + type.GUID.ToString("B");

            using (var key = Registry.ClassesRoot.CreateSubKey(subKeyName))
            {
                if (key == null)
                {
                    throw new ApplicationException("Failed to create sub key: " + subKeyName);
                }

                key.SetValue(string.Empty, description);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds additional info to the registry to allow the shell to discover the oject as shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <param name="progId">The prog id.</param>
        protected static void ComRegister(Type type, string description, string progId)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            if (description == null)
            {
                throw new ArgumentNullException(nameof(description));
            }
            if (description == progId)
            {
                throw new ArgumentNullException(nameof(progId));
            }

            RegistryExtensions.AddAsApprovedShellExtension(type, description);

            // Register the InfoTip COM object as the InfoTip handler. Only 1 handler can be installed for a file type.
            var subKeyName = progId + @"\ShellEx\{00021500-0000-0000-C000-000000000046}";

            using (var key = Registry.ClassesRoot.CreateSubKey(subKeyName))
            {
                if (key == null)
                {
                    throw new ApplicationException("Failed to create registry key: " + subKeyName);
                }

                key.SetValue(string.Empty, type.GUID.ToString("B"));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <param name="progId">The name.</param>
        protected static void ComUnregister(Type type, string description, string progId)
        {
            if (progId == null)
            {
                throw new ArgumentNullException(nameof(progId));
            }

            RegistryExtensions.RemoveAsApprovedShellExtension(type);

            using (var key = Registry.ClassesRoot.OpenSubKey(progId + @"\ShellEx\PropertySheetHandlers\", true))
            {
                key?.DeleteSubKey(description, false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        protected static void ComUnregister(Type type, string name)
        {
            Contract.Requires(type != null);
            Contract.Requires(!string.IsNullOrEmpty(name));

            RegistryExtensions.RemoveAsApprovedShellExtension(type);

            var keyName = @"Directory\ShellEx\CopyHookHandlers\" + name;

            using (var key = Registry.ClassesRoot.OpenSubKey(keyName, true))
            {
                key?.DeleteValue(type.GUID.ToString("B"), false);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
        /// </summary>
        /// <remarks>
        /// This function will only remove the COM registration from the specific ContextMenu. To prevent breaking
        /// other COM registrations other shell extensions are left untouched.
        /// It may be required to also remove the ProgID, this should be done in a separate method.
        /// </remarks>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <param name="progId">The prog id.</param>
        protected static void ComUnregister(Type type, string description, string progId)
        {
            Contract.Requires(type != null);
            Contract.Requires(!string.IsNullOrEmpty(description));
            Contract.Requires(!string.IsNullOrEmpty(progId));

            // Remove the ContextMenu COM registration.
            // Leave the 'ContextMenuHandlers' subkey intact, other handlers may also be installed.
            using (var contextMenuHandlersKey = Registry.ClassesRoot.OpenSubKey(progId + @"\ShellEx\ContextMenuHandlers", true))
            {
                contextMenuHandlersKey?.DeleteSubKey(description, false);
            }

            RegistryExtensions.RemoveAsApprovedShellExtension(type);
        }
Beispiel #6
0
        /// <summary>
        /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <param name="progId">The name.</param>
        protected static void ComUnregister(Type type, string description, string progId)
        {
            Contract.Requires(type != null);
            Contract.Requires(!string.IsNullOrEmpty(description));
            Contract.Requires(!string.IsNullOrEmpty(progId));

            RegistryExtensions.RemoveAsApprovedShellExtension(type);

            using (var key = Registry.ClassesRoot.OpenSubKey(progId + @"\ShellEx\PropertySheetHandlers\", true))
            {
                if (key != null)
                {
                    key.DeleteSubKey(description, false);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Adds additional info to the registry to allow the shell to discover the oject as shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <param name="progId">The prog id.</param>
        protected static void ComRegister(Type type, string description, string progId)
        {
            Contract.Requires(type != null);
            Contract.Requires(!string.IsNullOrEmpty(description));
            Contract.Requires(!string.IsNullOrEmpty(progId));

            RegistryExtensions.AddAsApprovedShellExtension(type, description);

            // Register the InfoTip COM object as the InfoTip handler. Only 1 handler can be installed for a file type.
            //var subKeyName = progId + @"\ShellEx\{00021500-0000-0000-C000-000000000046}";
            //using (var key = Registry.ClassesRoot.CreateSubKey(subKeyName))
            //{
            //    if (key == null)
            //        throw new ApplicationException("Failed to create registry key: " + subKeyName);

            //    key.SetValue(string.Empty, type.GUID.ToString("B"));
            //}
        }
Beispiel #8
0
        /// <summary>
        /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        protected static void ComUnregister(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            // Only try to remove when it was registered.
            if (IsShell60OrHigher())
            {
                return;
            }

            using (var key = Registry.ClassesRoot.OpenSubKey(ColumnHandlersKeyName, true))
            {
                key?.DeleteSubKey(type.GUID.ToString("B"), false);
            }

            RegistryExtensions.RemoveAsApprovedShellExtension(type);
        }
        /// <summary>
        /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        protected static void ComUnregister(Type type)
        {
            Contract.Requires(type != null);

            // Only try to remove when it was registered.
            if (IsShell60OrHigher())
            {
                return;
            }

            using (var key = Registry.ClassesRoot.OpenSubKey(ColumnHandlersKeyName, true))
            {
                if (key != null)
                {
                    key.DeleteSubKey(type.GUID.ToString("B"), false);
                }
            }

            RegistryExtensions.RemoveAsApprovedShellExtension(type);
        }
Beispiel #10
0
        /// <summary>
        /// Adds additional info to the registry to allow the shell to discover the oject as shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <param name="progId">The prog id.</param>
        protected static void ComRegister(Type type, string description, string progId)
        {
            Contract.Requires(type != null);
            Contract.Requires(!string.IsNullOrEmpty(description));
            Contract.Requires(!string.IsNullOrEmpty(progId));

            RegistryExtensions.AddAsApprovedShellExtension(type, description);

            // Register the object as a property sheet handler.
            var subKeyName = progId + @"\ShellEx\PropertySheetHandlers\" + description;

            using (var key = Registry.ClassesRoot.CreateSubKey(subKeyName))
            {
                if (key == null)
                {
                    throw new ApplicationException("Failed to create sub key: " + subKeyName);
                }

                key.SetValue(string.Empty, type.GUID.ToString("B"));
            }
        }
Beispiel #11
0
        /// <summary>
        /// Adds additional info to the registry to allow the shell to discover the oject as shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="name">The name.</param>
        /// <param name="description">The description.</param>
        protected static void ComRegister(Type type, string name, string description)
        {
            Contract.Requires(type != null);
            Contract.Requires(!string.IsNullOrEmpty(name));
            Contract.Requires(!string.IsNullOrEmpty(description));

            RegistryExtensions.AddAsApprovedShellExtension(type, description);

            // Register the CopyHook COM object as a copy hook handler.
            var keyName = @"Directory\ShellEx\CopyHookHandlers\" + name;

            using (var key = Registry.ClassesRoot.CreateSubKey(keyName))
            {
                if (key == null)
                {
                    throw new ApplicationException("Failed to open registry key: " + keyName);
                }

                key.SetValue(string.Empty, type.GUID.ToString("B"));
            }
        }
Beispiel #12
0
        /// <summary>
        /// Adds additional info to the registry to allow the shell to discover the oject as shell extension.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="description">The description.</param>
        /// <param name="progId">The prog id.</param>
        protected static void ComRegister(Type type, string description, string progId)
        {
            if (progId == null)
            {
                throw new ArgumentNullException(nameof(progId));
            }

            RegistryExtensions.AddAsApprovedShellExtension(type, description);

            // Register the ContextMenu COM object as the ContextMenu handler.
            var subKeyName = progId + @"\ShellEx\ContextMenuHandlers\" + description;

            using (var key = Registry.ClassesRoot.CreateSubKey(subKeyName))
            {
                if (key == null)
                {
                    throw new ApplicationException("Failed to create sub key: " + subKeyName);
                }

                key.SetValue(string.Empty, type.GUID.ToString("B"));
            }
        }
Beispiel #13
0
 /// <summary>
 /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="progId">The prog id.</param>
 protected static void ComUnregister(Type type, string progId)
 {
     RegistryExtensions.RemoveAsApprovedShellExtension(type);
 }
Beispiel #14
0
 /// <summary>
 /// Removed the additional info from the registry that allowed the shell to discover the shell extension.
 /// </summary>
 /// <param name="type">The type.</param>
 /// <param name="progId">The prog id.</param>
 protected static void ComUnregister(Type type, string progId)
 {
     Contract.Requires(type != null);
     RegistryExtensions.RemoveAsApprovedShellExtension(type);
 }