Skip to content

Commit 423553f

Browse files
authored
Add files via upload
1 parent cd4e097 commit 423553f

File tree

9 files changed

+5139
-0
lines changed

9 files changed

+5139
-0
lines changed

src/313/CSReg.cs

Lines changed: 956 additions & 0 deletions
Large diffs are not rendered by default.

src/313/CloseExplorerWindows.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
class Program
5+
{
6+
// Import the necessary Windows API functions
7+
[DllImport("user32.dll", SetLastError = true)]
8+
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
9+
10+
[DllImport("user32.dll", SetLastError = true)]
11+
[return: MarshalAs(UnmanagedType.Bool)]
12+
public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
13+
14+
[DllImport("user32.dll")]
15+
public static extern bool IsWindowVisible(IntPtr hWnd);
16+
17+
// Message constants
18+
const uint WM_CLOSE = 0x0010;
19+
20+
static void Main()
21+
{
22+
// Look for windows with the class name "CabinetWClass" (Explorer windows)
23+
IntPtr hWnd = FindWindow("CabinetWClass", null);
24+
25+
// Loop to find and close all open Explorer windows
26+
while (hWnd != IntPtr.Zero)
27+
{
28+
try
29+
{
30+
// Check if the window is visible
31+
if (IsWindowVisible(hWnd))
32+
{
33+
// Send the WM_CLOSE message to close the window
34+
PostMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
35+
Console.WriteLine("Closed an Explorer window");
36+
}
37+
38+
// Find the next Explorer window
39+
hWnd = FindWindowEx(IntPtr.Zero, hWnd, "CabinetWClass", null);
40+
}
41+
catch (Exception ex)
42+
{
43+
Console.WriteLine($"Error closing window: {ex.Message}");
44+
}
45+
}
46+
}
47+
48+
// Import FindWindowEx to get the next window of the same class
49+
[DllImport("user32.dll", SetLastError = true)]
50+
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
51+
}

src/313/GetMoreProperties.cs

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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

Comments
 (0)