Example #1
0
        private void PopulatePropertyList(List <PropertyConfig> propertyList,
                                          PropertySystemNativeMethods.PropDescEnumFilter filter)
        {
            propertyList.Clear();
            IPropertyDescriptionList propertyDescriptionList = null;
            IPropertyDescription     propertyDescription     = null;
            Guid guid = new Guid(ShellIIDGuid.IPropertyDescriptionList);

            try
            {
                var hr = PropertySystemNativeMethods.PSEnumeratePropertyDescriptions(
                    filter, ref guid, out propertyDescriptionList);
                if (hr >= 0)
                {
                    propertyDescriptionList.GetCount(out uint count);
                    guid = new Guid(ShellIIDGuid.IPropertyDescription);

                    for (uint i = 0; i < count; i++)
                    {
                        propertyDescriptionList.GetAt(i, ref guid, out propertyDescription);

                        if (propertyDescription != null)
                        {
                            var shellProperty = new ShellPropertyDescription(propertyDescription);
                            var pc            = new PropertyConfig(shellProperty);
                            shellProperty.Dispose();        // Releases propertyDescription
                            propertyDescription = null;
                            GetInstalledProperty(pc, true); // Add search and alias info
                            propertyList.Add(pc);
                            DictInstalledProperties.Add(pc.CanonicalName, pc);
                        }
                    }
                }
            }
            finally
            {
                if (propertyDescriptionList != null)
                {
                    Marshal.ReleaseComObject(propertyDescriptionList);
                }
                if (propertyDescription != null)
                {
                    Marshal.ReleaseComObject(propertyDescription);
                }
            }
        }
Example #2
0
        public bool UnregisterCustomProperty(string canonicalName)
        {
            // The file is held in a more protected common area away from the editor
            var targetFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                                            "CustomWindowsProperties");
            var targetFileName = $"{targetFolder}{Path.DirectorySeparatorChar}{canonicalName}.propdesc";

            if (!File.Exists(targetFileName))
            {
                throw new Exception($"Installed property configuration file {targetFileName} is missing");
            }

            var result = PropertySystemNativeMethods.PSUnregisterPropertySchema(targetFileName);

            if (result == 0)
            {
                File.Delete(targetFileName);
                return(true);
            }

            MessageBox.Show($"Property unregistration failed with error code 0x{result:x}", "Error uninstalling property");

            return(false);
        }