2using System.Runtime.InteropServices;
10#pragma warning disable SA1602
11#pragma warning disable SA1611
12#pragma warning disable SA1615
50 [DllImport(
"user32.dll")]
56 [DllImport(
"user32.dll", CharSet = CharSet.Unicode)]
57 public static extern IntPtr
FindWindow(
string? lpClassName,
string lpWindowName);
62 [DllImport(
"user32.dll")]
63 public static extern int SendMessage(IntPtr hWnd,
int wMsg, IntPtr wParam, IntPtr lParam);
73 [DllImport(
"user32.dll")]
79 [DllImport(
"user32.dll", CharSet = CharSet.Unicode, SetLastError =
true)]
80 public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString,
int nMaxCount);
85 [DllImport(
"advapi32.dll", SetLastError =
true, CharSet = CharSet.Unicode)]
86 public static extern bool LogonUser(
string lpszUsername,
string? lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider, out IntPtr phToken);
91 [DllImport(
"kernel32.dll", SetLastError =
true, CharSet = CharSet.Unicode)]
97 [DllImport(
"kernel32.dll", SetLastError =
true, CharSet = CharSet.Unicode)]
103 [DllImport(
"kernel32.dll", SetLastError =
true, CharSet = CharSet.Unicode)]
109 [DllImport(
"kernel32.dll", SetLastError =
true, CharSet = CharSet.Unicode)]
115 [DllImport(
"kernel32.dll", SetLastError =
true, CharSet = CharSet.Unicode)]
121 [DllImport(
"dbghelp.dll", SetLastError =
true, CharSet = CharSet.Unicode)]
128 IntPtr userStreamParam,
129 IntPtr callbackParam);
134#pragma warning disable IDE0079
135#pragma warning disable CA2101
136 [DllImport(
"libsystemd.so.0", CharSet = CharSet.Ansi, BestFitMapping =
false, ThrowOnUnmappableChar =
true)]
137 public static extern int sd_notify(
int unset_environment, [MarshalAs(UnmanagedType.LPUTF8Str)]
string state);
138#pragma warning restore CA2101
139#pragma warning restore IDE0079
Native methods used by the code.
MiniDumpType
See https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/ne-minidumpapiset-minidump_type...
static int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowthreadprocessid.
static IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms684335(v=vs.85).aspx.
static uint ResumeThread(IntPtr hThread)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms685086(v=vs.85).aspx.
static uint SuspendThread(IntPtr hThread)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686345(v=vs.85).aspx.
static bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-enumchildwindows.
static int sd_notify(int unset_environment, [MarshalAs(UnmanagedType.LPUTF8Str)] string state)
See https://www.freedesktop.org/software/systemd/man/sd_notify.html.
static IntPtr FindWindow(string? lpClassName, string lpWindowName)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-findwindoww.
static bool MiniDumpWriteDump(IntPtr hProcess, uint processId, SafeHandle hFile, MiniDumpType dumpType, IntPtr expParam, IntPtr userStreamParam, IntPtr callbackParam)
See https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/nf-minidumpapiset-minidumpwrite...
static bool LogonUser(string lpszUsername, string? lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken)
See https://msdn.microsoft.com/en-us/library/windows/desktop/aa378184(v=vs.85).aspx.
delegate bool EnumWindowProc(IntPtr hwnd, IntPtr lParam)
See https://msdn.microsoft.com/en-us/library/ms633493(v=VS.85).aspx.
CreateSymbolicLinkFlags
See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinka#param...
@ AllowUnprivilegedCreate
static bool CloseHandle(IntPtr hObject)
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx.
static int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-sendmessage.
ThreadAccess
See https://msdn.microsoft.com/en-us/library/windows/desktop/ms686769(v=vs.85).aspx.
static bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, CreateSymbolicLinkFlags dwFlags)
See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinkw.
static int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount)
See https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-getwindowtextw.