|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | +using System.IO; |
| 4 | +using System.Collections.Generic; |
| 5 | + |
| 6 | +namespace GetMoreProperties |
| 7 | +{ |
| 8 | + internal class Program |
| 9 | + { |
| 10 | + static void Main() |
| 11 | + { |
| 12 | + string tempPath = Path.GetTempPath(); |
| 13 | + string filePath = Path.Combine(tempPath, "Properties.tmp"); |
| 14 | + |
| 15 | + List<string> matchingProperties = new List<string>(); |
| 16 | + |
| 17 | + PSEnumeratePropertyDescriptions(PROPDESC_ENUMFILTER.PDEF_ALL, typeof(IPropertyDescriptionList).GUID, out var list); |
| 18 | + for (var i = 0; i < list.GetCount(); i++) |
| 19 | + { |
| 20 | + var pd = list.GetAt(i, typeof(IPropertyDescription).GUID); |
| 21 | + |
| 22 | + pd.GetDisplayName(out var p); |
| 23 | + if (p != IntPtr.Zero) |
| 24 | + { |
| 25 | + var viewable = pd.GetTypeFlags(PROPDESC_TYPE_FLAGS.PDTF_ISVIEWABLE) == PROPDESC_TYPE_FLAGS.PDTF_ISVIEWABLE; |
| 26 | + |
| 27 | + if (viewable) |
| 28 | + { |
| 29 | + string dname = Marshal.PtrToStringUni(p); |
| 30 | + Marshal.FreeCoTaskMem(p); |
| 31 | + |
| 32 | + pd.GetCanonicalName(out p); |
| 33 | + string cname = Marshal.PtrToStringUni(p); |
| 34 | + Marshal.FreeCoTaskMem(p); |
| 35 | + |
| 36 | + if (!cname.StartsWith("System") && !cname.StartsWith("Icaros")) |
| 37 | + { |
| 38 | + matchingProperties.Add($"{dname};.{cname}"); |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + if (matchingProperties.Count > 0) |
| 45 | + { |
| 46 | + using (StreamWriter writer = new StreamWriter(filePath, false, System.Text.Encoding.Unicode)) |
| 47 | + { |
| 48 | + foreach (var property in matchingProperties) |
| 49 | + { |
| 50 | + writer.WriteLine(property); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + public struct PROPERTYKEY |
| 57 | + { |
| 58 | + public Guid fmtid; |
| 59 | + public int pid; |
| 60 | + } |
| 61 | + |
| 62 | + public enum PROPDESC_ENUMFILTER |
| 63 | + { |
| 64 | + PDEF_ALL = 0, |
| 65 | + PDEF_SYSTEM = 1, |
| 66 | + PDEF_NONSYSTEM = 2, |
| 67 | + PDEF_VIEWABLE = 3, |
| 68 | + PDEF_QUERYABLE = 4, |
| 69 | + PDEF_INFULLTEXTQUERY = 5, |
| 70 | + PDEF_COLUMN = 6, |
| 71 | + } |
| 72 | + |
| 73 | + [Flags] |
| 74 | + public enum PROPDESC_TYPE_FLAGS |
| 75 | + { |
| 76 | + PDTF_DEFAULT = 0, |
| 77 | + PDTF_MULTIPLEVALUES = 0x1, |
| 78 | + PDTF_ISINNATE = 0x2, |
| 79 | + PDTF_ISGROUP = 0x4, |
| 80 | + PDTF_CANGROUPBY = 0x8, |
| 81 | + PDTF_CANSTACKBY = 0x10, |
| 82 | + PDTF_ISTREEPROPERTY = 0x20, |
| 83 | + PDTF_INCLUDEINFULLTEXTQUERY = 0x40, |
| 84 | + PDTF_ISVIEWABLE = 0x80, |
| 85 | + PDTF_ISQUERYABLE = 0x100, |
| 86 | + PDTF_CANBEPURGED = 0x200, |
| 87 | + PDTF_SEARCHRAWVALUE = 0x400, |
| 88 | + PDTF_DONTCOERCEEMPTYSTRINGS = 0x800, |
| 89 | + PDTF_ALWAYSINSUPPLEMENTALSTORE = 0x1000, |
| 90 | + PDTF_ISSYSTEMPROPERTY = unchecked((int)0x80000000), |
| 91 | + PDTF_MASK_ALL = unchecked((int)0x80001fff), |
| 92 | + } |
| 93 | + |
| 94 | + [DllImport("propsys")] |
| 95 | + public static extern int PSEnumeratePropertyDescriptions(PROPDESC_ENUMFILTER filterOn, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IPropertyDescriptionList ppv); |
| 96 | + |
| 97 | + [ComImport, Guid("1F9FC1D0-C39B-4B26-817F-011967D3440E"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] |
| 98 | + public interface IPropertyDescriptionList |
| 99 | + { |
| 100 | + int GetCount(); |
| 101 | + [return: MarshalAs(UnmanagedType.Interface)] |
| 102 | + IPropertyDescription GetAt(int iElem, [MarshalAs(UnmanagedType.LPStruct)] Guid riid); |
| 103 | + } |
| 104 | + |
| 105 | + [ComImport, Guid("6F79D558-3E96-4549-A1D1-7D75D2288814"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] |
| 106 | + public interface IPropertyDescription |
| 107 | + { |
| 108 | + PROPERTYKEY GetPropertyKey(); |
| 109 | + [PreserveSig] int GetCanonicalName(out IntPtr zPtr); |
| 110 | + int GetPropertyType(); |
| 111 | + [PreserveSig] int GetDisplayName(out IntPtr zPtr); |
| 112 | + [PreserveSig] int GetEditInvitation(out IntPtr zPtr); |
| 113 | + PROPDESC_TYPE_FLAGS GetTypeFlags(PROPDESC_TYPE_FLAGS mask); |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments