using System; using System.Drawing; using System.Runtime.InteropServices; using System.Runtime.InteropServices.ComTypes; using System.Security; using System.Security.Principal; using System.Text; using System.Threading; using System.Windows.Forms; using Accessibility; using Microsoft.Win32; using Microsoft.Win32.SafeHandles; namespace ScreenConnect; [SuppressUnmanagedCodeSecurity] public static class WindowsNative { public struct MOUSEINPUT { public int dx; public int dy; public uint mouseData; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; } public struct KEYBDINPUT { public ushort wVk; public ushort wScan; public uint dwFlags; public uint time; public IntPtr dwExtraInfo; } public struct MOUSEINPUTWRAPPER { public int type; public MOUSEINPUT mi; } public struct KEYBDINPUTWRAPPER { public int type; public KEYBDINPUT ki; } public struct ICONINFO { public bool fIcon; public int xHotspot; public int yHotspot; public IntPtr hbmMask; public IntPtr hbmColor; } public struct CURSORINFO { public int cbSize; public int flags; public IntPtr hCursor; public CorePoint ptScreenPos; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct BLENDFUNCTION { public byte BlendOp; public byte BlendFlags; public byte SourceConstantAlpha; public byte AlphaFormat; } [Flags] public enum TernaryRasterOperations : uint { SRCCOPY = 0xCC0020u, CAPTUREBLT = 0x40000000u } public enum DeviceCap { BITSPIXEL = 12, LOGPIXELSX = 88, LOGPIXELSY = 90 } public struct BITMAPINFO { public BITMAPINFOHEADER bmiHeader; public unsafe fixed uint bmiColors[256]; } public struct BITMAPINFOHEADER { public int biSize; public int biWidth; public int biHeight; public short biPlanes; public short biBitCount; public int biCompression; public int biSizeImage; public int biXPelsPerMeter; public int biYPelsPerMeter; public int biClrUsed; public int biClrImportant; } public enum BitmapCompression : uint { BI_RGB } public struct BITMAP { public int bmType; public int bmWidth; public int bmHeight; public int bmWidthBytes; public short bmPlanes; public short bmBitsPixel; public IntPtr bmBits; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct RECT { public int left; public int top; public int right; public int bottom; } public struct COLORADJUSTMENT { public ushort caSize; public ushort caFlags; public ushort caIlluminantIndex; public ushort caRedGamma; public ushort caGreenGamma; public ushort caBlueGamma; public ushort caReferenceBlack; public ushort caReferenceWhite; public short caContrast; public short caBrightness; public short caColorfulness; public short caRedGreenTint; } public enum SizingWindowSide : uint { Left = 1u, Right, Top, TopLeft, TopRight, Bottom, BottomLeft, BottomRight } [Flags] public enum ProcessAccess { AllAccess = 0x10067B, CreateThread = 2, DuplicateHandle = 0x40, QueryInformation = 0x400, SetInformation = 0x200, Terminate = 1, VMOperation = 8, VMRead = 0x10, VMWrite = 0x20, Synchronize = 0x100000, MAXIMUM_ALLOWED = 0x2000000 } public struct SECURITY_ATTRIBUTES { public int nLength; public IntPtr lpSecurityDescriptor; public int bInheritHandle; } public struct PROCESS_INFORMATION { public IntPtr hProcess; public IntPtr hThread; public int dwProcessId; public int dwThreadId; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct _CPAU_PARAM { public int cbSize; public int dwProcessId; public bool bUseDefaultToken; public IntPtr hToken; public IntPtr lpApplicationName; public IntPtr lpCommandLine; public SECURITY_ATTRIBUTES ProcessAttributes; public SECURITY_ATTRIBUTES ThreadAttributes; public bool bInheritHandles; public int dwCreationFlags; public IntPtr lpEnvironment; public IntPtr lpCurrentDirectory; public STARTUPINFO StartupInfo; public PROCESS_INFORMATION ProcessInformation; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct _CPAU_RET_PARAM { public int cbSize; public bool bRetValue; public int dwLastErr; public PROCESS_INFORMATION ProcInfo; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct STARTUPINFO { public int cb; public IntPtr lpReserved; public IntPtr lpDesktop; public IntPtr lpTitle; public int dwX; public int dwY; public int dwXSize; public int dwYSize; public int dwXCountChars; public int dwYCountChars; public int dwFillAttribute; public STARTUPINFO_FLAGS dwFlags; public short wShowWindow; public short cbReserved2; public IntPtr lpReserved2; public IntPtr hStdInput; public IntPtr hStdOutput; public IntPtr hStdError; } [Flags] public enum STARTUPINFO_FLAGS : uint { STARTF_USESHOWWINDOW = 1u, STARTF_USESIZE = 2u, STARTF_USEPOSITION = 4u, STARTF_USECOUNTCHARS = 8u, STARTF_USEFILLATTRIBUTE = 0x10u, STARTF_RUNFULLSCREEN = 0x20u, STARTF_FORCEONFEEDBACK = 0x40u, STARTF_FORCEOFFFEEDBACK = 0x80u, STARTF_USESTDHANDLES = 0x100u } public enum SW { HIDE = 0, SHOWNORMAL = 1, SHOWMINIMIZED = 2, SHOWMAXIMIZED = 3, SHOWNOACTIVATE = 4, SHOW = 5, RESTORE = 9, SHOWDEFAULT = 10 } public enum SECURITY_IMPERSONATION_LEVEL { SecurityAnonymous, SecurityIdentification, SecurityImpersonation, SecurityDelegation } public enum TOKEN_TYPE { TokenPrimary = 1, TokenImpersonation } public struct TOKEN_MANDATORY_LABEL { public IntPtr Sid; public uint Attributes; } public struct TOKEN_STATISTICS { public ulong TokenId; public ulong AuthenticationId; public long ExpirationTime; public TOKEN_TYPE TokenType; public SECURITY_IMPERSONATION_LEVEL ImpersonationLevel; public uint DynamicCharged; public uint DynamicAvailable; public uint GroupCount; public uint PrivilegeCount; public ulong ModifiedId; } public enum TOKEN_INFORMATION_CLASS { TokenPrivileges = 3, TokenStatistics = 10, TokenElevationType = 18, TokenLinkedToken = 19, TokenElevation = 20, TokenIntegrityLevel = 25, TokenUIAccess = 26 } public struct SECURITY_LOGON_SESSION_DATA { public int Size; public LUID LogonId; public LSA_UNICODE_STRING UserName; public LSA_UNICODE_STRING LogonDomain; } public struct LSA_STRING { public ushort Length; public ushort MaximumLength; public IntPtr Buffer; } public struct LSA_UNICODE_STRING { public ushort Length; public ushort MaximumLength; public IntPtr Buffer; } [Flags] public enum CreateProcessFlags : uint { CREATE_NEW_CONSOLE = 0x10u, CREATE_UNICODE_ENVIRONMENT = 0x400u, DETACHED_PROCESS = 8u } public struct SecHandle { public IntPtr dwLower; public IntPtr dwUpper; } public struct SecBufferDesc { public uint ulVersion; public uint cBuffers; public unsafe SecBuffer* pBuffers; } public struct SecBuffer { public int cbBuffer; public uint BufferType; public unsafe byte* pvBuffer; } public struct SEC_WINNT_AUTH_IDENTITY { public unsafe char* User; public int UserLength; public unsafe char* Domain; public int DomainLength; public unsafe char* Password; public int PasswordLength; public int Flags; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_1 { [MarshalAs(UnmanagedType.LPWStr)] public string usri1_name; [MarshalAs(UnmanagedType.LPWStr)] public string usri1_password; public int usri1_password_age; public int usri1_priv; [MarshalAs(UnmanagedType.LPWStr)] public string usri1_home_dir; [MarshalAs(UnmanagedType.LPWStr)] public string usri1_comment; public int usri1_flags; [MarshalAs(UnmanagedType.LPWStr)] public string usri1_script_path; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_4 { [MarshalAs(UnmanagedType.LPWStr)] public string usri4_name; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_password; public int usri4_password_age; public int usri4_priv; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_home_dir; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_comment; public int usri4_flags; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_script_path; public int usri4_auth_flags; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_full_name; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_usr_comment; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_parms; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_workstations; public int usri4_last_logon; public int usri4_last_logoff; public int usri4_acct_expires; public int usri4_max_storage; public int usri4_units_per_week; public IntPtr usri4_logon_hours; public int usri4_bad_pw_count; public int usri4_num_logons; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_logon_server; public int usri4_country_code; public int usri4_code_page; public IntPtr usri4_user_sid; public int usri4_primary_group_id; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_profile; [MarshalAs(UnmanagedType.LPWStr)] public string usri4_home_dir_drive; public int usri4_password_expired; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_1003 { [MarshalAs(UnmanagedType.LPWStr)] public string usri1003_password; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_1007 { [MarshalAs(UnmanagedType.LPWStr)] public string usri1007_comment; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_1008 { public UF usri1008_flags; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_1017 { public int usri1017_acct_expires; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_20 { [MarshalAs(UnmanagedType.LPWStr)] public string usri20_name; [MarshalAs(UnmanagedType.LPWStr)] public string usri20_full_name; [MarshalAs(UnmanagedType.LPWStr)] public string usri20_comment; public UF usri20_flags; public int usri20_user_id; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct USER_INFO_23 { [MarshalAs(UnmanagedType.LPWStr)] public string usri23_name; [MarshalAs(UnmanagedType.LPWStr)] public string usri23_full_name; [MarshalAs(UnmanagedType.LPWStr)] public string usri23_comment; public UF usri23_flags; public IntPtr usri23_user_sid; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public struct LOCALGROUP_MEMBERS_INFO_3 { [MarshalAs(UnmanagedType.LPWStr)] public string lgrmi3_domainandname; } public enum UF { ACCOUNTDISABLE = 2 } [Flags] public enum SMTO { NORMAL = 0, BLOCK = 1, ABORTIFHUNG = 2, BROADCAST = 4, NOTIMEOUTIFNOTHUNG = 8, VALID = BLOCK | ABORTIFHUNG | BROADCAST | NOTIMEOUTIFNOTHUNG } public enum WM : uint { NULL = 0u, CREATE = 1u, DESTROY = 2u, MOVE = 3u, SIZE = 5u, ACTIVATE = 6u, SETFOCUS = 7u, KILLFOCUS = 8u, SETREDRAW = 11u, GETTEXT = 13u, GETTEXTLENGTH = 14u, PAINT = 15u, CLOSE = 16u, QUERYENDSESSION = 17u, ENDSESSION = 22u, ERASEBKGND = 20u, SHOWWINDOW = 24u, WININICHANGE = 26u, SETTINGCHANGE = WININICHANGE, ACTIVATEAPP = 28u, SETCURSOR = 32u, MOUSEACTIVATE = 33u, DRAWITEM = 43u, MEASUREITEM = 44u, QUERYDRAGICON = 55u, WINDOWPOSCHANGING = 70u, WINDOWPOSCHANGED = 71u, CONTEXTMENU = 123u, DISPLAYCHANGE = 126u, GETICON = 127u, SETICON = 128u, NCCREATE = 129u, NCCALCSIZE = 131u, NCHITTEST = 132u, NCPAINT = 133u, NCACTIVATE = 134u, NCLBUTTONDOWN = 161u, NCLBUTTONUP = 162u, NCRBUTTONDOWN = 164u, NCRBUTTONUP = 165u, KEYDOWN = 256u, KEYUP = 257u, CHAR = 258u, SYSKEYDOWN = 260u, SYSKEYUP = 261u, SYSCHAR = 262u, COMMAND = 273u, SYSCOMMAND = 274u, TIMER = 275u, INITMENU = 278u, INITMENUPOPUP = 279u, CTLCOLORLISTBOX = 308u, MOUSEMOVE = 512u, LBUTTONDOWN = 513u, LBUTTONUP = 514u, LBUTTONDBLCLK = 515u, RBUTTONDOWN = 516u, RBUTTONUP = 517u, RBUTTONDBLCLK = 518u, MOUSEWHEEL = 522u, PARENTNOTIFY = 528u, SIZING = 532u, MOUSEHOVER = 673u, MOUSELEAVE = 675u, DESTROYCLIPBOARD = 775u, DRAWCLIPBOARD = 776u, CLIPBOARDUPDATE = 797u, CHANGECBCHAIN = 781u, HOTKEY = 786u, PRINT = 791u, USER = 1024u } public enum EM : uint { SETRECT = 179u } [Flags] public enum EXECUTION_STATE : uint { ES_CONTINUOUS = 0x80000000u, ES_DISPLAY_REQUIRED = 2u, ES_SYSTEM_REQUIRED = 1u } public enum SC { MINIMIZE = 61472, MAXIMIZE = 61488, CLOSE = 61536, RESTORE = 61728 } public struct WINDOWPOS { public IntPtr hwnd; public IntPtr hwndInsertAfter; public int x; public int y; public int cx; public int cy; public SWP flags; } public enum GW : uint { HWNDFIRST, HWNDLAST, HWNDNEXT, HWNDPREV, OWNER, CHILD, ENABLEDPOPUP } public struct NCCALCSIZE_PARAMS { public RECT rect0; public RECT rect1; public RECT rect2; public IntPtr lppos; } public delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lparam); public delegate bool EnumDesktopsProc(string desktop, IntPtr lparam); public delegate bool EnumWindowStationProc(string lpszWindowStation, IntPtr lParam); public delegate IntPtr WndProc(IntPtr hwnd, WM uMsg, IntPtr wParam, IntPtr lParam); public enum GWL { WNDPROC = -4, ID = -12, STYLE = -16, EXSTYLE = -20, USERDATA = -21 } public enum LWA : uint { COLORKEY = 1u, ALPHA } [Flags] public enum AW : uint { ACTIVATE = 0x20000u, BLEND = 0x80000u, SLIDE = 0x40000u } [Flags] public enum MenuFlags { BYCOMMAND = 0, BYPOSITION = 0x400 } [Flags] public enum SWP : uint { NOSIZE = 1u, NOMOVE = 2u, NOZORDER = 4u, NOREDRAW = 8u, NOACTIVATE = 0x10u, FRAMECHANGED = 0x20u, SHOWWINDOW = 0x40u, HIDEWINDOW = 0x80u, NOCOPYBITS = 0x100u, NOOWNERZORDER = 0x200u, NOSENDCHANGING = 0x400u, DEFERERASE = 0x2000u, ASYNCWINDOWPOS = 0x4000u } [Flags] public enum WS_EX : uint { ACCEPTFILES = 0x10u, APPWINDOW = 0x40000u, CLIENTEDGE = 0x200u, COMPOSITED = 0x2000000u, CONTEXTHELP = 0x400u, CONTROLPARENT = 0x10000u, DLGMODALFRAME = 1u, LAYERED = 0x80000u, LAYOUTRTL = 0x400000u, LEFTSCROLLBAR = 0x4000u, MDICHILD = 0x40u, NOACTIVATE = 0x8000000u, NOINHERITLAYOUT = 0x100000u, NOPARENTNOTIFY = 4u, OVERLAPPEDWINDOW = 0x300u, PALETTEWINDOW = 0x188u, RIGHT = 0x1000u, RTLREADING = 0x2000u, STATICEDGE = 0x20000u, TOOLWINDOW = 0x80u, TOPMOST = 8u, TRANSPARENT = 0x20u, WINDOWEDGE = 0x100u } [Flags] public enum WS : uint { OVERLAPPED = 0u, POPUP = 0x80000000u, CHILD = 0x40000000u, MINIMIZE = 0x20000000u, VISIBLE = 0x10000000u, DISABLED = 0x8000000u, CLIPSIBLINGS = 0x4000000u, CLIPCHILDREN = 0x2000000u, MAXIMIZE = 0x1000000u, BORDER = 0x800000u, DLGFRAME = 0x400000u, VSCROLL = 0x200000u, HSCROLL = 0x100000u, SYSMENU = 0x80000u, THICKFRAME = 0x40000u, GROUP = 0x20000u, TABSTOP = 0x10000u, MINIMIZEBOX = GROUP, MAXIMIZEBOX = TABSTOP, CAPTION = BORDER | DLGFRAME, TILED = 0u, ICONIC = MINIMIZE, SIZEBOX = THICKFRAME, TILEDWINDOW = CAPTION | SYSMENU | THICKFRAME | GROUP | TABSTOP, OVERLAPPEDWINDOW = TILEDWINDOW, POPUPWINDOW = POPUP | BORDER | SYSMENU, CHILDWINDOW = CHILD } public struct MONITORINFO { public int cbSize; public RECT rcMonitor; public RECT rcWork; public int dwFlags; } public struct WINDOWPLACEMENT { public int length; public int flags; public SW showCmd; public int ptMinPosition_x; public int ptMinPosition_y; public int ptMaxPosition_x; public int ptMaxPosition_y; public int rcNormalPosition_left; public int rcNormalPosition_top; public int rcNormalPosition_right; public int rcNormalPosition_bottom; } public struct MENUITEMINFO { public int cbSize; public MIIM fMask; public MFT fType; public MFS fState; public int wID; public IntPtr hSubMenu; public IntPtr hbmpChecked; public IntPtr hbmpUnchecked; public IntPtr dwItemData; public IntPtr dwTypeData; public int cch; public IntPtr hbmpItem; } [Flags] public enum MIIM { STATE = 1, ID = 2, STRING = 0x40, TYPE = 0x10, DATA = 0x20, FTYPE = 0x100 } [Flags] public enum MFS { CHECKED = 8, DEFAULT = 0x1000, DISABLED = 3, GRAYED = DISABLED, HILITE = 0x80 } [Flags] public enum MFT { STRING = 0, SEPARATOR = 0x800 } public struct WINDOWINFO { public int cbSize; public RECT rcWindow; public RECT rcClient; public WS dwStyle; public WS_EX dwExStyle; public uint dwWindowStatus; public uint cxWindowBorders; public uint cyWindowBorders; public ushort atomWindowType; public ushort wCreatorVersion; } public struct FLASHWINFO { public uint cbSize; public IntPtr hwnd; public FLASHW dwFlags; public uint uCount; public uint dwTimeout; } [Flags] public enum FLASHW : uint { TRAY = 2u, TIMERNOFG = 0xCu } [Flags] public enum ACCESS_MASK : uint { MAXIMUM_ALLOWED = 0x2000000u, GENERIC_READ = 0x80000000u, GENERIC_WRITE = 0x40000000u, GENERIC_EXECUTE = 0x20000000u, GENERIC_ALL = 0x10000000u, DESKTOP_READOBJECTS = 1u, DESKTOP_CREATEWINDOW = 2u, DESKTOP_CREATEMENU = 4u, DESKTOP_HOOKCONTROL = 8u, DESKTOP_JOURNALRECORD = 0x10u, DESKTOP_JOURNALPLAYBACK = 0x20u, DESKTOP_ENUMERATE = 0x40u, DESKTOP_WRITEOBJECTS = 0x80u, DESKTOP_SWITCHDESKTOP = 0x100u, DESKTOP_ALL = DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK | DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP, WINSTA_ALL_ACCESS = 0x37Fu } public enum WH { MSGFILTER = -1, JOURNALRECORD, JOURNALPLAYBACK, KEYBOARD, GETMESSAGE, CALLWNDPROC, CBT, SYSMSGFILTER, MOUSE, HARDWARE, DEBUG, SHELL, FOREGROUNDIDLE, CALLWNDPROCRET, KEYBOARD_LL, MOUSE_LL } public struct KBDLLHOOKSTRUCT { public Keys vkCode; public uint scanCode; public LLKHF flags; public uint time; public IntPtr dwExtraInfo; } [Flags] public enum KF { ALTDOWN = 0x2000, DLGMODE = 0x800, EXTENDED = 0x100, MENUMODE = 0x1000, REPEAT = 0x4000, UP = 0x8000 } [Flags] public enum LLKHF { EXTENDED = 1, LOWER_IL_INJECTED = 2, INJECTED = 0x10, ALTDOWN = 0x20, UP = 0x80 } public delegate IntPtr HOOKPROC(int nCode, IntPtr wParam, IntPtr lParam); public enum EVENT { OBJECT_CREATE = 32768, OBJECT_SHOW = 32770, OBJECT_SELECTION = 32774, OBJECT_SELECTIONWITHIN = 32777, OBJECT_STATECHANGE = 32778, OBJECT_LOCATIONCHANGE = 32779 } public delegate void WINEVENTPROC(IntPtr hWinEventHook, EVENT @event, IntPtr hwnd, int idObject, int idChild, int idEventThread, uint dwmsEventTime); [Flags] public enum WINEVENT { OUTOFCONTEXT = 0, SKIPOWNTHREAD = 1, SKIPOWNPROCESS = 2, INCONTEXT = 4, _32BITCALLER = 0x8000, VALID = SKIPOWNTHREAD | SKIPOWNPROCESS | INCONTEXT | _32BITCALLER } public enum WDA : uint { NONE = 0u, MONITOR = 1u, EXCLUDEFROMCAPTURE = 17u } [Flags] public enum SPIF : uint { None = 0u, UPDATEINIFILE = 1u, SENDCHANGE = 2u } public enum SPI : uint { GETSCREENSAVEACTIVE = 16u, SETSCREENSAVEACTIVE = 17u, SETDESKWALLPAPER = 20u, SETDRAGFULLWINDOWS = 37u, GETDRAGFULLWINDOWS = 38u, SETMINIMIZEDMETRICS = 44u, SETWORKAREA = 47u, GETLOWPOWERACTIVE = 83u, GETPOWEROFFACTIVE = 84u, SETLOWPOWERACTIVE = 85u, SETPOWEROFFACTIVE = 86u, GETMOUSEHOVERTIME = 102u, SETMOUSEHOVERTIME = 103u, GETDESKWALLPAPER = 115u } public struct MINIMIZEDMETRICS { public int cbSize; public int iWidth; public int iHorzGap; public int iVertGap; public int iArrange; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct SERVICE_STATUS { public uint dwServiceType; public uint dwCurrentState; public uint dwControlsAccepted; public uint dwWin32ExitCode; public uint dwServiceSpecificExitCode; public uint dwCheckPoint; public uint dwWaitHint; } [Flags] public enum SERVICE_CONTROL : uint { STOP = 1u } [Flags] public enum ExitWindows : uint { Reboot = 2u, Force = 4u } [Flags] public enum ShutdownReason : uint { SHTDN_REASON_MAJOR_APPLICATION = 0x40000u, SHTDN_REASON_MINOR_MAINTENANCE = 1u, SHTDN_REASON_FLAG_PLANNED = 0x80000000u } [Flags] public enum TOKEN : uint { TOKEN_ASSIGN_PRIMARY = 1u, TOKEN_DUPLICATE = 2u, TOKEN_IMPERSONATE = 4u, TOKEN_QUERY = 8u, TOKEN_QUERY_SOURCE = 0x10u, TOKEN_ADJUST_PRIVILEGES = 0x20u, TOKEN_ADJUST_GROUPS = 0x40u, TOKEN_ADJUST_DEFAULT = 0x80u, TOKEN_ALL_ACCESS = TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT, MAXIMUM_ALLOWED = 0x2000000u } public struct TOKEN_PRIVILEGES { public uint PrivilegeCount; public LUID Luid; public uint Attributes; } public struct LUID { public uint LowPart; public int HighPart; } public struct WTS_SESSION_INFO { public int SessionId; public unsafe char* pWinStationName; public WTS_CONNECTSTATE_CLASS State; } public enum WTS_CONNECTSTATE_CLASS { Active = 0, Connected = 1, Disconnected = 4, Idle = 5 } public enum WTS_INFO_CLASS { WTSUserName = 5, WTSDomainName = 7, WTSConnectState = 8, WTSClientProtocolType = 16 } public struct PROPERTYKEY { public static readonly PROPERTYKEY FriendlyNameKey = CreatePropertyKey(new Guid(2757502286u, 57116, 20221, 128, 32, 103, 209, 70, 168, 80, 224), 14); public static readonly PROPERTYKEY FormFactorKey = CreatePropertyKey(new Guid(497408003u, 54418, 20189, 140, 35, 224, 192, byte.MaxValue, 238, 127, 14), 0); public static readonly PROPERTYKEY DeviceIndexesKey = CreatePropertyKey(new Guid(1867695463, 864, 19410, 150, 23, 204, 191, 20, 33, 201, 57), 4); public static readonly PROPERTYKEY SystemModeKey = CreatePropertyKey(new Guid(1867695463, 864, 19410, 150, 23, 204, 191, 20, 33, 201, 57), 2); public static readonly PROPERTYKEY FeatureModeKey = CreatePropertyKey(new Guid(1867695463, 864, 19410, 150, 23, 204, 191, 20, 33, 201, 57), 5); public static readonly PROPERTYKEY GainControlKey = CreatePropertyKey(new Guid(1867695463, 864, 19410, 150, 23, 204, 191, 20, 33, 201, 57), 9); public static readonly PROPERTYKEY EchoSuppressionKey = CreatePropertyKey(new Guid(1867695463, 864, 19410, 150, 23, 204, 191, 20, 33, 201, 57), 10); public Guid fmtid; public int pid; private static PROPERTYKEY CreatePropertyKey(Guid fmtid, int pid) { return new PROPERTYKEY { fmtid = fmtid, pid = pid }; } } [StructLayout(LayoutKind.Explicit, Pack = 1)] public struct PROPVARIANT { [FieldOffset(0)] public VarEnum vt; [FieldOffset(2)] public short wReserved1; [FieldOffset(4)] public short wReserved2; [FieldOffset(6)] public short wReserved3; [FieldOffset(8)] public int intVal; [FieldOffset(8)] public long lVal; [FieldOffset(8)] public short boolVal; } public enum VarEnum : short { VT_I4 = 3, VT_BOOL = 11 } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("886d8eeb-8cf2-4446-8d02-cdba1dbdcf99")] public interface IPropertyStore { int GetCount(); PROPERTYKEY GetAt(int iProp); PROPVARIANT GetValue(ref PROPERTYKEY key); void SetValue(ref PROPERTYKEY key, ref PROPVARIANT propvar); } public struct WAVEFORMATEXTENSIBLE { public ushort wFormatTag; public short nChannels; public int nSamplesPerSec; public int nAvgBytesPerSec; public short nBlockAlign; public short wBitsPerSample; public short cbSize; public short Samples; public int dwChannelMask; public Guid SubFormat; } public struct WAVEHDR { public IntPtr lpData; public int dwBufferLength; public int dwBytesRecorded; public IntPtr dwUser; public int dwFlags; public int dwLoops; public IntPtr lpNext; public IntPtr reserved; } [StructLayout(LayoutKind.Sequential, Size = 12)] public struct MMTIME { public uint wType; public uint cb; } public struct WAVEOUTCAPS { public short wMid; public short wPid; public uint vDriverVersion; public unsafe fixed char szPname[32]; public int dwFormats; public short wChannels; public short wReserved1; public int dwSupport; } public struct WAVEINCAPS { public short wMid; public short wPid; public uint vDriverVersion; public unsafe fixed char szPname[32]; public int dwFormats; public short wChannels; public short wReserved1; } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("D666063F-1587-4E43-81F1-B948E807363F")] public interface IMMDevice { [return: MarshalAs(UnmanagedType.IUnknown)] object Activate([MarshalAs(UnmanagedType.LPStruct)] Guid iid, int dwClsCtx, IntPtr pActivationParams); IPropertyStore OpenPropertyStore(int stgmAccess); [return: MarshalAs(UnmanagedType.LPWStr)] string GetID(); int GetState(); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E")] public interface IMMDeviceCollection { uint GetCount(); IMMDevice Item(int nDevice); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("A95664D2-9614-4F35-A746-DE8DB63617E6")] public interface IMMDeviceEnumerator { IMMDeviceCollection EnumAudioEndpoints(EDataFlow dataFlow, int dwStateMask); IMMDevice GetDefaultAudioEndpoint(EDataFlow dataFlow, ERole role); IMMDevice GetDevice([MarshalAs(UnmanagedType.LPWStr)] string pwstrId); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("1CB9AD4C-DBFA-4c32-B178-C2F568A703B2")] public interface IAudioClient { void Initialize(AUDCLNT_SHAREMODE ShareMode, int StreamFlags, long hnsBufferDuration, long hnsPeriodicity, IntPtr pFormat, Guid AudioSessionGuid); uint GetBufferSize(); void GetStreamLatency(); uint GetCurrentPadding(); void IsFormatSupported(AUDCLNT_SHAREMODE ShareMode, IntPtr pFormat, out IntPtr ppClosestMatch); void GetMixFormat(out IntPtr ppDeviceFormat); void GetDevicePeriod(); void Start(); void Stop(); void Reset(); void SetEventHandle(); [return: MarshalAs(UnmanagedType.IUnknown)] object GetService([MarshalAs(UnmanagedType.LPStruct)] Guid riid); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("C8ADBD64-E71E-48a0-A4DE-185C395CD317")] public interface IAudioCaptureClient { void GetBuffer(out IntPtr ppData, out uint pNumFramesToRead, out int pdwFlags, out ulong pu64DevicePosition, out ulong pu64QPCPosition); void ReleaseBuffer(uint NumFramesRead); int GetNextPacketSize(); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("F294ACFC-3146-4483-A7BF-ADDCA7C260E2")] public interface IAudioRenderClient { IntPtr GetBuffer(uint NumFramesRequested); void ReleaseBuffer(uint NumFramesWritten, int dwFlags); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("93014887-242D-4068-8A15-CF5E93B90FE3")] public interface IAudioStreamVolume { uint GetChannelCount(); void SetChannelVolume(); void GetChannelVolume(); unsafe void SetAllVolumes(uint dwCount, float* pfVolumes); } public enum EDataFlow { eRender, eCapture, eAll } public enum ERole { eConsole, eMultimedia, eCommunications } public enum AUDCLNT_SHAREMODE { SHARED, EXCLUSIVE } public enum EndpointFormFactor { RemoteNetworkDevice, Speakers, LineLevel, Headphones, Microphone, Headset, Handset, UnknownDigitalPassthrough, SPDIF, DigitalAudioDisplayDevice, UnknownFormFactor, EndpointFormFactor_enum_count } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B")] public interface IDesktopWallpaper { void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID, [MarshalAs(UnmanagedType.LPWStr)] string wallpaper); [return: MarshalAs(UnmanagedType.LPWStr)] string GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID); [return: MarshalAs(UnmanagedType.LPWStr)] string GetMonitorDevicePathAt(uint monitorIndex); [return: MarshalAs(UnmanagedType.U4)] uint GetMonitorDevicePathCount(); [return: MarshalAs(UnmanagedType.Struct)] RECT GetMonitorRECT([MarshalAs(UnmanagedType.LPWStr)] string monitorID); void SetBackgroundColor([MarshalAs(UnmanagedType.U4)] uint color); [return: MarshalAs(UnmanagedType.U4)] uint GetBackgroundColor(); void SetPosition([MarshalAs(UnmanagedType.I4)] DESKTOP_WALLPAPER_POSITION position); [return: MarshalAs(UnmanagedType.I4)] DESKTOP_WALLPAPER_POSITION GetPosition(); void Enable(); void AdvanceSlideshow([MarshalAs(UnmanagedType.LPWStr)] string monitorID, [MarshalAs(UnmanagedType.I4)] DESKTOP_SLIDESHOW_DIRECTION direction); DESKTOP_SLIDESHOW_OPTIONS GetStatus(); void Enable(bool enable); } public enum DESKTOP_WALLPAPER_POSITION { DWPOS_CENTER, DWPOS_TILE, DWPOS_STRETCH, DWPOS_FIT, DWPOS_FILL, DWPOS_SPAN } public enum DESKTOP_SLIDESHOW_DIRECTION { DSD_FORWARD, DSD_BACKWARD } public enum DESKTOP_SLIDESHOW_OPTIONS { DSO_SHUFFLED = 1 } [ComImport] [Guid("C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD")] public class DesktopWallpaperClass { } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("d8ad0f58-5494-4102-97c5-ec798e59bcf4")] public interface IMediaObject { void GetStreamCount(); uint GetInputStreamInfo(int dwInputStreamIndex); uint GetOutputStreamInfo(int dwOutputStreamIndex); void GetInputType(); void GetOutputType(); void SetInputType(int dwInputStreamIndex, [In] ref DMO_MEDIA_TYPE pmt, int dwFlags); void SetOutputType(int dwOutputStreamIndex, [In] ref DMO_MEDIA_TYPE pmt, int dwFlags); void GetInputCurrentType(); void GetOutputCurrentType(); void GetInputSizeInfo(); void GetOutputSizeInfo(); void GetInputMaxLatency(); void SetInputMaxLatency(); void Flush(); void Discontinuity(int dwInputStreamIndex); void AllocateStreamingResources(); void FreeStreamingResources(); void GetInputStatus(); void ProcessInput(int dwInputStreamIndex, IMediaBuffer pBuffer, int dwFlags, long rtTimestamp, long rtTimelength); void ProcessOutput(int dwFlags, int cOutputBufferCount, [In][Out][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] DMO_OUTPUT_DATA_BUFFER[] pOutputBuffers, out int pdwStatus); void Lock(); } [ComImport] [Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] public class MMDeviceEnumerator { } [ComImport] [Guid("F447B69E-1884-4A7E-8055-346F74D6EDB3")] public class Resampler { } [ComImport] [Guid("745057c7-f353-4f2d-a7ee-58434477730e")] public class VoiceCapturer { } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("59eff8b9-938c-4a26-82f2-95cb84cdc837")] public interface IMediaBuffer { void SetLength(int cbLength); void GetMaxLength(out int pcbMaxLength); void GetBufferAndLength(IntPtr ppBuffer, IntPtr pcbLength); } [StructLayout(LayoutKind.Sequential, Pack = 8)] public struct DMO_OUTPUT_DATA_BUFFER { [MarshalAs(UnmanagedType.Interface)] public IMediaBuffer pBuffer; public int dwStatus; public long rtTimestamp; public long rtTimelength; } public struct DMO_MEDIA_TYPE { public Guid majortype; public Guid subtype; public bool bFixedSizeSamples; public bool bTemporalCompression; public int lSampleSize; public Guid formattype; public IntPtr pUnk; public int cbFormat; public IntPtr pbFormat; } public struct SHChangeNotifyEntry { public IntPtr pidl; public int fRecursive; } [Flags] public enum SHGFI { ICON = 0x100, DISPLAYNAME = 0x200, TYPENAME = 0x400, ATTRIBUTES = 0x800, EXETYPE = 0x2000, SYSICONINDEX = 0x4000, ATTR_SPECIFIED = 0x20000, LARGEICON = 0, SMALLICON = 1, OPENICON = 2, SHELLICONSIZE = 4, USEFILEATTRIBUTES = 0x10 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct SHFILEINFO { public IntPtr hIcon; public int iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string szDisplayName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)] public string szTypeName; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct FILEGROUPDESCRIPTOR { public uint cItems; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct FILEDESCRIPTOR { public FD dwFlags; public Guid clsid; public int sizelcx; public int sizelcy; public int pointlx; public int pointly; public uint dwFileAttributes; public FILETIME ftCreationTime; public FILETIME ftLastAccessTime; public FILETIME ftLastWriteTime; public uint nFileSizeHigh; public uint nFileSizeLow; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string cFileName; } public enum FD : uint { CLSID = 1u, SIZEPOINT = 2u, ATTRIBUTES = 4u, CREATETIME = 8u, ACCESSTIME = 0x10u, WRITESTIME = 0x20u, FILESIZE = 0x40u, PROGRESSUI = 0x4000u } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("000214EE-0000-0000-C000-000000000046")] public interface IShellLink { void GetPath([Out][MarshalAs(UnmanagedType.LPStr)] StringBuilder pszFile, int cchMaxPath, IntPtr pfd, SLGP fFlags); void GetIDList(out IntPtr ppidl); void SetIDList(IntPtr pidl); void GetDescription([Out][MarshalAs(UnmanagedType.LPStr)] StringBuilder pszName, int cchMaxName); void SetDescription([MarshalAs(UnmanagedType.LPStr)] string pszName); void GetWorkingDirectory([Out][MarshalAs(UnmanagedType.LPStr)] StringBuilder pszDir, int cchMaxPath); void SetWorkingDirectory([MarshalAs(UnmanagedType.LPStr)] string pszDir); void GetArguments([Out][MarshalAs(UnmanagedType.LPStr)] StringBuilder pszArgs, int cchMaxPath); void SetArguments([MarshalAs(UnmanagedType.LPStr)] string pszArgs); void GetHotkey(out short pwHotkey); void SetHotkey(short wHotkey); [PreserveSig] int GetShowCmd(out int piShowCmd); void SetShowCmd(int iShowCmd); [PreserveSig] int GetIconLocation([Out][MarshalAs(UnmanagedType.LPStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon); void SetIconLocation([MarshalAs(UnmanagedType.LPStr)] string pszIconPath, int iIcon); void SetRelativePath([MarshalAs(UnmanagedType.LPStr)] string pszPathRel, int dwReserved); void Resolve(IntPtr hwnd, SLR fFlags); void SetPath([MarshalAs(UnmanagedType.LPStr)] string pszFile); } [ComImport] [Guid("00021401-0000-0000-C000-000000000046")] public class ShellLinkClass { } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("000214E6-0000-0000-C000-000000000046")] public interface IShellFolder { void ParseDisplayName(IntPtr hwnd, IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string pszDisplayName, out uint pchEaten, out IntPtr ppidl, IntPtr pdwAttributes); void EnumObjects(); [return: MarshalAs(UnmanagedType.Interface)] object BindToObject(IntPtr pidl, IntPtr pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid riid); void BindToStorage(); void CompareIDs(); [return: MarshalAs(UnmanagedType.Interface)] object CreateViewObject(IntPtr hwndOwner, [MarshalAs(UnmanagedType.LPStruct)] Guid riid); void GetAttributesOf(); [return: MarshalAs(UnmanagedType.Interface)] object GetUIObjectOf(IntPtr hwndOwner, int cidl, [MarshalAs(UnmanagedType.LPArray)] IntPtr[] apidl, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, IntPtr rgfReserved); void GetDisplayNameOf(); void SetNameOf(); } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("00000122-0000-0000-C000-000000000046")] public interface IDropTarget { void DragEnter(IDataObject pDataObj, int grfKeyState, long pt, ref DragDropEffects pdwEffect); void DragLeave(); void DragOver(int grfKeyState, long pt, ref DragDropEffects pdwEffect); void Drop(IDataObject pDataObj, int grfKeyState, long pt, ref DragDropEffects pdwEffect); } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("00000002-0000-0000-C000-000000000046")] public interface IMalloc { void Alloc(); void Realloc(); [PreserveSig] void Free(IntPtr pv); void GetSize(); void DidAlloc(); void HeapMinimize(); } [Flags] public enum SLGP { SHORTPATH = 1, UNCPRIORITY = 2, RAWPATH = 4 } [Flags] public enum SLR { NO_UI = 1 } [ComImport] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")] public interface IShellItem { [return: MarshalAs(UnmanagedType.Interface)] object BindToHandler(IntPtr pbc, [MarshalAs(UnmanagedType.LPStruct)] Guid bhid, [MarshalAs(UnmanagedType.LPStruct)] Guid riid); IShellItem GetParent(); [return: MarshalAs(UnmanagedType.LPWStr)] string GetDisplayName(SIGDN sigdnName); void GetAttributes(); void Compare(); } public enum SIGDN : uint { NORMALDISPLAY = 0u, FILESYSPATH = 2147844096u } public enum HSHELL : uint { ACCESSIBILITYSTATE = 11u, ACTIVATESHELLWINDOW = 3u, APPCOMMAND = 12u, GETMINRECT = 5u, LANGUAGE = 8u, REDRAW = 6u, TASKMAN = 7u, WINDOWCREATED = 1u, WINDOWDESTROYED = 2u, WINDOWACTIVATED = 4u, WINDOWREPLACED = 13u, WINDOWREPLACING = 14u, ENDTASK = 10u, FLASH = 32774u, RUDEAPPACTIVATED = 32772u } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct AVICOMPRESSOPTIONS { public uint fccType; public uint fccHandler; public uint dwKeyFrameEvery; public uint dwQuality; public uint dwBytesPerSecond; public uint dwFlags; public IntPtr lpFormat; public uint cbFormat; public IntPtr lpParms; public uint cbParms; public uint dwInterleaveEvery; } [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct AVISTREAMINFO { public uint fccType; public uint fccHandler; public uint dwFlags; public uint dwCaps; public ushort wPriority; public ushort wLanguage; public uint dwScale; public uint dwRate; public uint dwStart; public uint dwLength; public uint dwInitialFrames; public uint dwSuggestedBufferSize; public uint dwQuality; public uint dwSampleSize; public RECT rcFrame; public uint dwEditCount; public uint dwFormatChangeCount; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)] public ushort[] szName; } [Guid("3D8B0590-F691-11d2-8EA9-006097DF5BD4")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] public interface IDataObjectAsyncCapability { void SetAsyncMode(bool fDoOpAsync); bool GetAsyncMode(); void StartOperation(IBindCtx pbcReserved); bool InOperation(); void EndOperation(int hResult, IBindCtx pbcReserved, int dwEffects); } public enum LOAD_LIBRARY_FLAGS : uint { NONE = 0u, LOAD_LIBRARY_AS_DATAFILE = 2u, LOAD_LIBRARY_AS_IMAGE_RESOURCE = 0x20u } public enum PROCESS_MITIGATION_POLICY { ProcessSignaturePolicy = 8, ProcessImageLoadPolicy = 10 } public enum PROCESS_MITIGATION_IMAGE_LOAD_POLICY { PreferSystem32Images = 4 } public enum LOAD_LIBRARY_SEARCH { APPLICATION_DIR = 512, DEFAULT_DIRS = 4096, SYSTEM32 = 2048, USER_DIRS = 1024 } public enum DWMWINDOWATTRIBUTE : uint { NCRenderingEnabled = 1u, NCRenderingPolicy, TransitionsForceDisabled, AllowNCPaint, CaptionButtonBounds, NonClientRtlLayout, ForceIconicRepresentation, Flip3DPolicy, ExtendedFrameBounds, HasIconicBitmap, DisallowPeek, ExcludedFromPeek, Cloak, Cloaked, FreezeRepresentation } public enum DWMNCRENDERINGPOLICY : uint { USEWINDOWSTYLE = 1u, DISABLED, ENABLED, LAST } public struct MARGINS { public int left; public int right; public int top; public int bottom; } public struct LASTINPUTINFO { public uint cbSize; public uint dwTime; } public struct MEMORYSTATUSEX { public uint dwLength; public int dwMemoryLoad; public long ullTotalPhys; public long ullAvailPhys; public long ullTotalPageFile; public long ullAvailPageFile; public long ullTotalVirtual; public long ullAvailVirtual; public long ullAvailExtendedVirtual; } [Flags] public enum MEM { MEM_COMMIT = 0x1000, MEM_DECOMMIT = 0x4000, MEM_RELEASE = 0x8000, MEM_RESERVE = 0x2000, MEM_FREE = 0x10000 } [Flags] public enum PAGE { PAGE_NOACCESS = 1, PAGE_READONLY = 2, PAGE_READWRITE = 4, PAGE_WRITECOPY = 8, PAGE_EXECUTE = 0x10, PAGE_EXECUTE_READ = 0x20, PAGE_EXECUTE_READWRITE = 0x40, PAGE_EXECUTE_WRITECOPY = 0x80, PAGE_GUARD = 0x100, PAGE_NOCACHE = 0x200, PAGE_WRITECOMBINE = 0x400 } [Flags] public enum IMAGE_SCN : uint { IMAGE_SCN_MEM_DISCARDABLE = 0x2000000u, IMAGE_SCN_MEM_EXECUTE = 0x20000000u, IMAGE_SCN_MEM_READ = 0x40000000u, IMAGE_SCN_MEM_WRITE = 0x80000000u, IMAGE_SCN_CNT_CODE = 0x20u, IMAGE_SCN_CNT_INITIALIZED_DATA = 0x40u, IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x80u } public struct OSVERSIONINFOEX { public int dwOSVersionInfoSize; public int dwMajorVersion; public int dwMinorVersion; public int dwBuildNumber; public int dwPlatformId; public unsafe fixed byte szCSDVersion[128]; public short wServicePackMajor; public short wServicePackMinor; public short wSuiteMask; public byte wProductType; public byte wReserved; } public struct SYSTEM_INFO { public ushort wProcessorArchitecture; public ushort wReserved; public uint dwPageSize; public IntPtr lpMinimumApplicationAddress; public IntPtr lpMaximumApplicationAddress; public IntPtr dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public ushort wProcessorLevel; public ushort wProcessorRevision; } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("00000001-0000-0000-C000-000000000046")] public interface IClassFactory { [return: MarshalAs(UnmanagedType.Interface)] object CreateInstance([MarshalAs(UnmanagedType.Interface)] object pUnkOuter, [In][MarshalAs(UnmanagedType.LPStruct)] Guid riid); void LockServer(int fLock); } public struct POINT { private long x; private long y; } [Flags] public enum PIPE_ACCESS { DUPLEX = 3, INBOUND = 1, OUTBOUND = 2 } [Flags] public enum PIPE_MODE { REJECT_REMOTE_CLIENTS = 8 } [Flags] public enum MOVEFILE { REPLACE_EXISTING = 1, COPY_ALLOWED = 2, DELAY_UNTIL_REBOOT = 4, WRITE_THROUGH = 8, CREATE_HARDLINK = 0x10, FAIL_IF_NOT_TRACKABLE = 0x20 } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("00000109-0000-0000-C000-000000000046")] public interface IPersistStream { int GetClassID(out Guid pClassID); int IsDirty(); void Load(IStream pstm); void Save(IStream pstm, int fClearDirty); void GetSizeMax(ulong[] pcbSize); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("89BCB740-6119-101A-BCB7-00DD010655AF")] public interface IFilter { int Init(int grfFlags, int cAttributes, IntPtr aAttributes); STAT_CHUNK GetChunk(); void GetText(ref uint pcwcBuffer, [Out][MarshalAs(UnmanagedType.LPArray)] char[] awcBuffer); void GetValue(); void BindRegion(); } public struct STAT_CHUNK { public unsafe fixed byte data[128]; } public struct REPARSE_DATA_BUFFER { public IO_REPARSE_TAG ReparseTag; public ushort ReparseDataLength; public ushort Reserved; public REPARSE_DATA_BUFFER_Union Union; } public enum IO_REPARSE_TAG : uint { SYMLINK = 2684354572u, MOUNT_POINT = 2684354563u } [StructLayout(LayoutKind.Explicit)] public struct REPARSE_DATA_BUFFER_Union { [FieldOffset(0)] public REPARSE_DATA_BUFFER_SymbolicLinkReparseBuffer SymbolicLinkReparseBuffer; [FieldOffset(0)] public REPARSE_DATA_BUFFER_MountPointReparseBuffer MountPointReparseBuffer; } public struct REPARSE_DATA_BUFFER_SymbolicLinkReparseBuffer { public ushort SubstituteNameOffset; public ushort SubstituteNameLength; public ushort PrintNameOffset; public ushort PrintNameLength; public uint Flags; public unsafe fixed byte PathBuffer[2000]; } public struct REPARSE_DATA_BUFFER_MountPointReparseBuffer { public ushort SubstituteNameOffset; public ushort SubstituteNameLength; public ushort PrintNameOffset; public ushort PrintNameLength; public unsafe fixed byte PathBuffer[2000]; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct DOC_INFO_3 { public string pDocName; public string pOutputFile; public string pDataType; public int dwFlags; } public struct PRINTER_DEFAULTS { public IntPtr pDatatype; public IntPtr pDevMode; public int DesiredAccess; } public struct DRIVER_INFO_8 { public uint cVersion; public IntPtr pName; public IntPtr pEnvironment; public IntPtr pDriverPath; public IntPtr pDataFile; public IntPtr pConfigFile; public IntPtr pHelpFile; public IntPtr pDependentFiles; public IntPtr pMonitorName; public IntPtr pDefaultDataType; public IntPtr pszzPreviousNames; public ulong ftDriverDate; public ulong dwlDriverVersion; public IntPtr pszMfgName; public IntPtr pszOEMUrl; public IntPtr pszHardwareID; public IntPtr pszProvider; public IntPtr pszPrintProcessor; public IntPtr pszVendorSetup; public IntPtr pszzColorProfiles; public IntPtr pszInfPath; public uint dwPrinterDriverAttributes; public IntPtr pszzCoreDriverDependencies; public ulong ftMinInboxDriverVerDate; public ulong dwlMinInboxDriverVerVersion; } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("0c733a30-2a1c-11ce-ade5-00aa0044773d")] public interface IXpsPrintJobStream { unsafe int Read(byte* pv, int cb); unsafe int Write(byte* pv, int cb); void Close(); } [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] [Guid("5ab89b06-8194-425f-ab3b-d7a96e350161")] public interface IXpsPrintJob { void Cancel(); void GetJobStatus(); } public delegate bool MagImageScalingCallback(IntPtr hwnd, IntPtr srcdata, MAGIMAGEHEADER srcheader, IntPtr destdata, MAGIMAGEHEADER destheader, RECT unclipped, RECT clipped, IntPtr dirty); public struct MAGIMAGEHEADER { public int width; public int height; public Guid format; public int stride; public int offset; public IntPtr cbSize; } public struct Pointl { [MarshalAs(UnmanagedType.I4)] public int x; [MarshalAs(UnmanagedType.I4)] public int y; } public struct DevMode { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string dmDeviceName; [MarshalAs(UnmanagedType.U2)] public ushort dmSpecVersion; [MarshalAs(UnmanagedType.U2)] public ushort dmDriverVersion; [MarshalAs(UnmanagedType.U2)] public ushort dmSize; [MarshalAs(UnmanagedType.U2)] public ushort dmDriverExtra; [MarshalAs(UnmanagedType.U4)] public uint dmFields; public Pointl dmPosition; [MarshalAs(UnmanagedType.U4)] public uint dmDisplayOrientation; [MarshalAs(UnmanagedType.U4)] public uint dmDisplayFixedOutput; [MarshalAs(UnmanagedType.I2)] public short dmColor; [MarshalAs(UnmanagedType.I2)] public short dmDuplex; [MarshalAs(UnmanagedType.I2)] public short dmYResolution; [MarshalAs(UnmanagedType.I2)] public short dmTTOption; [MarshalAs(UnmanagedType.I2)] public short dmCollate; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string dmFormName; [MarshalAs(UnmanagedType.U2)] public ushort dmLogPixels; [MarshalAs(UnmanagedType.U4)] public uint dmBitsPerPel; [MarshalAs(UnmanagedType.U4)] public uint dmPelsWidth; [MarshalAs(UnmanagedType.U4)] public uint dmPelsHeight; [MarshalAs(UnmanagedType.U4)] public uint dmDisplayFlags; [MarshalAs(UnmanagedType.U4)] public uint dmDisplayFrequency; [MarshalAs(UnmanagedType.U4)] public uint dmICMMethod; [MarshalAs(UnmanagedType.U4)] public uint dmICMIntent; [MarshalAs(UnmanagedType.U4)] public uint dmMediaType; [MarshalAs(UnmanagedType.U4)] public uint dmDitherType; [MarshalAs(UnmanagedType.U4)] public uint dmReserved1; [MarshalAs(UnmanagedType.U4)] public uint dmReserved2; [MarshalAs(UnmanagedType.U4)] public uint dmPanningWidth; [MarshalAs(UnmanagedType.U4)] public uint dmPanningHeight; } public enum DISP_CHANGE { Successful = 0, Restart = 1, Failed = -1, BadMode = -2, NotUpdated = -3, BadFlags = -4, BadParam = -5, BadDualView = -6 } [Flags] public enum ChangeDisplaySettingsFlags : uint { CDS_NONE = 0u, CDS_UPDATEREGISTRY = 1u, CDS_TEST = 2u, CDS_FULLSCREEN = 4u, CDS_GLOBAL = 8u, CDS_SET_PRIMARY = 0x10u, CDS_VIDEOPARAMETERS = 0x20u, CDS_ENABLE_UNSAFE_MODES = 0x100u, CDS_DISABLE_UNSAFE_MODES = 0x200u, CDS_RESET = 0x40000000u, CDS_RESET_EX = 0x20000000u, CDS_NORESET = 0x10000000u } public enum PRODUCT { DATACENTER_A_SERVER_CORE = 145, STANDARD_A_SERVER_CORE } public static readonly int SendInputMessageSize = Marshal.SizeOf(typeof(MOUSEINPUTWRAPPER)); public static readonly int BitmapStructureSize = Marshal.SizeOf(typeof(BITMAP)); public static readonly int BitmapInfoStructureSize = Marshal.SizeOf(typeof(BITMAPINFO)); public static readonly int BitmapInfoHeaderStructureSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)); public static readonly int CursorInfoSize = Marshal.SizeOf(typeof(CURSORINFO)); public static readonly int SecurityAttributesSize = Marshal.SizeOf(typeof(SECURITY_ATTRIBUTES)); public static readonly int WindowInfoSize = Marshal.SizeOf(typeof(WINDOWINFO)); public const int INPUT_MOUSE = 0; public const int INPUT_KEYBOARD = 1; public const int INPUT_HARDWARE = 2; public const uint KEYEVENTF_EXTENDEDKEY = 1u; public const uint KEYEVENTF_KEYUP = 2u; public const uint KEYEVENTF_UNICODE = 4u; public const uint KEYEVENTF_SCANCODE = 8u; public const uint XBUTTON1 = 1u; public const uint XBUTTON2 = 2u; public const uint MOUSEEVENTF_MOVE = 1u; public const uint MOUSEEVENTF_LEFTDOWN = 2u; public const uint MOUSEEVENTF_LEFTUP = 4u; public const uint MOUSEEVENTF_RIGHTDOWN = 8u; public const uint MOUSEEVENTF_RIGHTUP = 16u; public const uint MOUSEEVENTF_MIDDLEDOWN = 32u; public const uint MOUSEEVENTF_MIDDLEUP = 64u; public const uint MOUSEEVENTF_XDOWN = 128u; public const uint MOUSEEVENTF_XUP = 256u; public const uint MOUSEEVENTF_WHEEL = 2048u; public const uint MOUSEEVENTF_HWHEEL = 4096u; public const uint MOUSEEVENTF_VIRTUALDESK = 16384u; public const uint MOUSEEVENTF_ABSOLUTE = 32768u; public const int DI_IMAGE = 2; public const int DI_MASK = 1; public const uint DIB_RGB_COLORS = 0u; public const int LOGON32_LOGON_NETWORK = 3; public const int LOGON32_LOGON_BATCH = 4; public const uint HWND_BROADCAST = 65535u; public const uint SE_PRIVILEGE_ENABLED = 2u; public const uint SE_PRIVILEGE_REMOVED = 4u; public const int CF_UNICODETEXT = 13; public const int MAXPNAMELEN = 32; public const ushort WAVE_FORMAT_PCM = 1; public const int DEVICE_STATE_ACTIVE = 1; public const int AUDCLNT_STREAMFLAGS_LOOPBACK = 131072; public const int AUDCLNT_E_DEVICE_INVALIDATED = -2004287484; public const int AUDCLNT_E_BUFFER_TOO_LARGE = -2004287482; public const int E_NOTFOUND = -2147023728; public const int CLSCTX_ALL = 23; public const int WAVE_MAPPER = -1; public const int WHDR_DONE = 1; public const uint TIME_BYTES = 4u; public const int MMSYSERR_BADDEVICEID = 2; public const int MMSYSERR_INVALHANDLE = 5; public const int AVICOMPRESSF_KEYFRAMES = 4; public const int AVICOMPRESSF_VALID = 8; public const uint MA_ACTIVATE = 1u; public const uint MA_ACTIVATEANDEAT = 2u; public const int DV_E_DVASPECT = -2147221397; public const int DV_E_FORMATETC = -2147221404; public const int DV_E_TYMED = -2147221399; public const string CFSTR_FILECONTENTS = "FileContents"; public const string CFSTR_FILEDESCRIPTORW = "FileGroupDescriptorW"; public const string CFSTR_FILEDESCRIPTORA = "FileGroupDescriptor"; public const string CFSTR_PREFERREDDROPEFFECT = "Preferred DropEffect"; public const int MAX_PATH = 260; public const int LPTR = 64; public const int STGM_READ = 0; public const int URLMON_OPTION_USERAGENT = 268435457; public const int URLMON_OPTION_USERAGENT_REFRESH = 268435458; public const int EnumCurrentSettings = -1; [DllImport("user32", EntryPoint = "SendInput", SetLastError = true)] public static extern uint SendKeyboardInput(uint nInputs, ref KEYBDINPUTWRAPPER pInputs, int cbSize); [DllImport("user32", EntryPoint = "SendInput", SetLastError = true)] public static extern uint SendMouseInput(uint nInputs, ref MOUSEINPUTWRAPPER pInputs, int cbSize); [DllImport("user32", SetLastError = true)] public static extern int MapVirtualKey(int uCode, uint uMapType); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetKeyboardLayout(int idThread); [DllImport("user32", CharSet = CharSet.Auto)] public static extern short VkKeyScan(char ch); [DllImport("user32", CharSet = CharSet.Auto)] public unsafe static extern bool GetKeyboardState(byte* lpKeyState); [DllImport("user32")] public static extern short GetKeyState(Keys nVirtKey); [DllImport("user32", CharSet = CharSet.Auto)] public unsafe static extern bool GetKeyboardLayoutName(char* pwszKLID); [DllImport("user32", CharSet = CharSet.Auto)] public unsafe static extern int ToUnicode(int wVirtKey, int wScanCode, byte* lpKeyState, char* pwszBuff, int cchBuff, uint wFlags); [DllImport("user32", SetLastError = true)] public static extern bool BlockInput(bool fBlockIt); [DllImport("user32", SetLastError = true)] public static extern bool LockWorkStation(); [DllImport("user32")] public static extern IntPtr GetMessageExtraInfo(); [DllImport("user32", SetLastError = true)] public static extern IntPtr CreateIconIndirect(ref ICONINFO icon); [DllImport("user32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool GetIconInfo(IntPtr hIcon, ref ICONINFO pIconInfo); [DllImport("user32", SetLastError = true)] public static extern bool GetCursorInfo(ref CURSORINFO cursorInfo); [DllImport("user32", SetLastError = true)] public static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName); [DllImport("user32", SetLastError = true)] public static extern bool DestroyCursor(IntPtr hCursor); [DllImport("user32", SetLastError = true)] public static extern int DrawIconEx(IntPtr hDC, int xLeft, int yTop, IntPtr hIcon, int cxWidth, int cyWidth, int istepIfAniCur, IntPtr hbrFlickerFreeDraw, int diFlags); [DllImport("user32", SetLastError = true)] public static extern bool SetCursorPos(int X, int Y); [DllImport("user32", SetLastError = true)] public static extern int GetGuiResources(IntPtr hProcess, int uiFlags); [DllImport("gdi32", SetLastError = true)] public static extern bool BitBlt(IntPtr hdcDst, int xDst, int yDst, int cx, int cy, IntPtr hdcSrc, int xSrc, int ySrc, TernaryRasterOperations ulRop); [DllImport("gdi32")] public static extern bool StretchBlt(IntPtr hdcDest, int nXOriginDest, int nYOriginDest, int nWidthDest, int nHeightDest, IntPtr hdcSrc, int nXOriginSrc, int nYOriginSrc, int nWidthSrc, int nHeightSrc, TernaryRasterOperations dwRop); [DllImport("gdi32")] public static extern int SetStretchBltMode(IntPtr hdc, int iStretchMode); [DllImport("gdi32")] public unsafe static extern bool SetColorAdjustment(IntPtr hdc, COLORADJUSTMENT* lpca); [DllImport("gdi32")] public static extern int SelectClipRgn(IntPtr hdc, IntPtr hrgn); [DllImport("gdi32")] public static extern int IntersectClipRect(IntPtr hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect); [DllImport("gdi32")] public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData); [DllImport("gdi32")] public static extern bool DeleteDC(IntPtr hdc); [DllImport("user32")] public static extern IntPtr GetDC(IntPtr hWnd); [DllImport("user32")] public static extern IntPtr GetWindowDC(IntPtr hWnd); [DllImport("user32")] public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC); [DllImport("user32")] public static extern bool DestroyIcon(IntPtr hIcon); [DllImport("gdi32", SetLastError = true)] public static extern int GetDIBits(IntPtr hdc, IntPtr hbmp, uint uStartScan, uint cScanLines, IntPtr lpvBits, ref BITMAPINFO lpbmi, uint uUsage); [DllImport("gdi32")] public static extern uint SetPixel(IntPtr hdc, int X, int Y, uint crColor); [DllImport("gdi32")] public static extern IntPtr CreateBitmap(int nWidth, int nHeight, int cPlanes, int cBitsPerPel, IntPtr lpvBits); [DllImport("gdi32", SetLastError = true)] public static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFO pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset); [DllImport("gdi32")] public static extern bool DeleteObject(IntPtr hObject); [DllImport("gdi32")] public static extern int GetDeviceCaps(IntPtr hdc, int nIndex); [DllImport("gdi32", SetLastError = true)] public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight); [DllImport("gdi32", SetLastError = true)] public static extern IntPtr CreateCompatibleDC(IntPtr hdc); [DllImport("gdi32", ExactSpelling = true, SetLastError = true)] public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj); [DllImport("gdi32", SetLastError = true)] public static extern int GetObject(IntPtr hgdiobj, int cbBuffer, ref IntPtr lpvObject); [DllImport("gdi32", EntryPoint = "GetObject", SetLastError = true)] public static extern int GetObjectBitmap(IntPtr hObject, int nCount, ref BITMAP lpObject); [DllImport("gdi32")] public static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy); [DllImport("gdi32", SetLastError = true)] public static extern bool SetViewportOrgEx(IntPtr hdc, int x, int y, out POINT lppt); [DllImport("gdi32", SetLastError = true)] public static extern bool OffsetViewportOrgEx(IntPtr hdc, int x, int y, out POINT lppt); [DllImport("gdi32", SetLastError = true)] public static extern int SaveDC(IntPtr hdc); [DllImport("gdi32", SetLastError = true)] public static extern bool RestoreDC(IntPtr hdc, int nSavedDC); [DllImport("user32")] public static extern bool ClientToScreen(IntPtr hWnd, ref Point lpPoint); [DllImport("advapi32", SetLastError = true)] public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken); [DllImport("kernel32", SetLastError = true)] public static extern IntPtr OpenProcess(ProcessAccess dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandle, int dwProcessId); [DllImport("advapi32", SetLastError = true)] public static extern bool ImpersonateLoggedOnUser(IntPtr hToken); [DllImport("advapi32", SetLastError = true)] public static extern bool RevertToSelf(); [DllImport("psapi", SetLastError = true)] public static extern int GetModuleBaseName(IntPtr hProcess, IntPtr hModule, StringBuilder lpBaseName, int nSize); [DllImport("psapi", SetLastError = true)] public static extern bool EnumProcessModules(IntPtr hProcess, ref IntPtr lphModule, int cb, out int lpcbNeeded); [DllImport("psapi", SetLastError = true)] public static extern bool EnumProcesses(int[] processIds, int arraySizeBytes, out int bytesCopied); [DllImport("kernel32", SetLastError = true)] public static extern bool ProcessIdToSessionId(int dwProcessId, out int pSessionId); [DllImport("advapi32", SetLastError = true)] public static extern bool GetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, IntPtr TokenInformation, int TokenInformationLength, out int ReturnLength); [DllImport("advapi32", SetLastError = true)] public static extern bool SetTokenInformation(IntPtr TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, IntPtr TokenInformation, int TokenInformationLength); [DllImport("secur32", SetLastError = true)] public static extern int LsaConnectUntrusted(out IntPtr LsaHandle); [DllImport("secur32", SetLastError = true)] public static extern int LsaDeregisterLogonProcess(IntPtr LsaHandle); [DllImport("secur32", SetLastError = true)] public static extern int LsaLookupAuthenticationPackage(IntPtr LsaHandle, ref LSA_STRING PackageName, out uint AuthenticationPackage); [DllImport("secur32", SetLastError = true)] public unsafe static extern int LsaGetLogonSessionData(ulong* LogonId, SECURITY_LOGON_SESSION_DATA** ppLogonSessionData); [DllImport("secur32", SetLastError = true)] public unsafe static extern int LsaFreeReturnBuffer(void* Buffer); [DllImport("userenv", SetLastError = true)] public static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit); [DllImport("userenv", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool DestroyEnvironmentBlock(IntPtr lpEnvironment); [DllImport("advapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool CreateProcessAsUser(IntPtr hToken, string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles, CreateProcessFlags dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo, out PROCESS_INFORMATION lpProcessInformation); [DllImport("secur32", SetLastError = true)] public unsafe static extern int AcquireCredentialsHandle(string pszPrincipal, string pszPackage, int fCredentialUse, void* pvLogonID, SEC_WINNT_AUTH_IDENTITY* pAuthData, void* pGetKeyFn, void* pvGetKeyArgument, SecHandle* phCredential, ulong* ptsExpiry); [DllImport("secur32", SetLastError = true)] public unsafe static extern int InitializeSecurityContext(SecHandle* phCredential, SecHandle* phContext, string pszTargetName, int fContextReq, int Reserved1, int TargetDataRep, SecBufferDesc* pInput, int Reserved2, SecHandle* phNewContext, SecBufferDesc* pOutput, int* pfContextAttr, ulong* ptsExpiry); [DllImport("secur32", SetLastError = true)] public unsafe static extern int FreeCredentialsHandle(SecHandle* phCredential); [DllImport("secur32", SetLastError = true)] public unsafe static extern int DeleteSecurityContext(SecHandle* phContext); [DllImport("winsta", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool WinStationQueryInformation(IntPtr hServer, int LogonId, int WinStationInformationClass, StringBuilder pWinStationInformation, int WinStationInformationLength, out int pReturnLength); [DllImport("advapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool CredProtect(bool fAsSelf, [MarshalAs(UnmanagedType.LPTStr)] string pszCredentials, int cchCredentials, IntPtr pszProtectedCredentials, ref int pcchMaxChars, out int ProtectionType); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserAdd(string servername, int level, ref USER_INFO_1 buf, out int parm_err); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserDel(string servername, string username); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetLocalGroupAddMembers(string servername, string groupname, int level, ref LOCALGROUP_MEMBERS_INFO_3 buf, int totalentries); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetLocalGroupDelMembers(string servername, string groupname, int level, ref LOCALGROUP_MEMBERS_INFO_3 buf, int totalentries); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserEnum(string servername, int level, int filter, out IntPtr bufptr, uint prefmaxlen, out int entriesread, out int totalentries, ref int resume_handle); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserGetInfo(string servername, string username, int level, out IntPtr bufpt); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserSetInfo(string servername, string username, int level, ref USER_INFO_1003 buf, ref int parm_err); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserSetInfo(string servername, string username, int level, ref USER_INFO_1007 buf, ref int parm_err); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserSetInfo(string servername, string username, int level, ref USER_INFO_1008 buf, ref int parm_err); [DllImport("netapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int NetUserSetInfo(string servername, string username, int level, ref USER_INFO_1017 buf, ref int parm_err); [DllImport("userenv", CharSet = CharSet.Unicode)] public static extern int CreateProfile(string pszUserSid, string pszUserName, StringBuilder pszProfilePath, int cchProfilePath); [DllImport("userenv", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool DeleteProfile(string lpSidString, string lpProfilePath, string lpComputerName); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool PostMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SendMessageTimeout(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam, SMTO fuFlags, int uTimeout, out IntPtr lpdwResult); [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32", SetLastError = true)] public static extern bool PrintWindow(IntPtr hwnd, IntPtr hdcBlt, int nFlags); [DllImport("kernel32", SetLastError = true)] public static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags); [DllImport("user32", SetLastError = true)] public static extern bool GetUserObjectInformation(IntPtr hObj, int nIndex, [Out] StringBuilder pvInfo, uint nLength, out uint lpnLengthNeeded); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr CreateDesktop(string desktopName, string device, string deviceMode, int flags, ACCESS_MASK accessMask, IntPtr attributes); [DllImport("user32")] public static extern bool SwitchDesktop(IntPtr hDesktop); [DllImport("user32", SetLastError = true)] public static extern IntPtr OpenInputDesktop(uint dwFlags, bool fInherit, ACCESS_MASK dwDesiredAccess); [DllImport("user32", SetLastError = true)] public static extern IntPtr OpenDesktop(string lpszDesktop, uint dwFlags, bool fInherit, ACCESS_MASK dwDesiredAccess); [DllImport("user32", SetLastError = true)] public static extern bool CloseDesktop(IntPtr hDesktop); [DllImport("user32")] public static extern IntPtr WindowFromPoint(Point point); [DllImport("user32", SetLastError = true)] public static extern IntPtr UpdateWindow(IntPtr hWnd); [DllImport("user32", PreserveSig = false, SetLastError = true)] public static extern int GetWindowThreadProcessId(IntPtr hWnd); [DllImport("user32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWindow(IntPtr hWnd); [DllImport("user32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32")] public static extern IntPtr GetClassLongPtr(IntPtr hWnd, int nIndex); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetForegroundWindow(); [DllImport("user32", SetLastError = true)] public static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect); [DllImport("user32", SetLastError = true)] public static extern bool GetClientRect(IntPtr hWnd, ref RECT lpRect); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int ShowWindow(IntPtr hWnd, SW nCmdShow); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr GetTopWindow(IntPtr hWnd); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetWindow(IntPtr hWnd, GW uCmd); [DllImport("user32", SetLastError = true)] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32", SetLastError = true)] public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam); [DllImport("user32")] public static extern bool EnumChildWindows(IntPtr hWndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam); [DllImport("user32", SetLastError = true)] public static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumWindowsProc lpfn, IntPtr lParam); [DllImport("user32")] public static extern bool EnumDesktops(IntPtr hwinsta, EnumDesktopsProc lpEnumFunc, IntPtr lParam); [DllImport("user32")] public static extern bool EnumWindowStations(EnumWindowStationProc lpEnumFunc, IntPtr lParam); [DllImport("user32", CharSet = CharSet.Unicode)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); [DllImport("user32", CharSet = CharSet.Unicode)] public static extern bool IsIconic(IntPtr hWnd); [DllImport("user32")] public static extern bool IsWindowVisible(IntPtr hWnd); [DllImport("user32")] public static extern IntPtr GetAncestor(IntPtr hWnd, uint gaFlags); [DllImport("user32")] public static extern IntPtr GetLastActivePopup(IntPtr hWnd); [DllImport("user32", SetLastError = true)] public static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public unsafe static extern int GetClassName(IntPtr hWnd, char* lpClassName, int nMaxCount); [DllImport("user32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FlashWindowEx(ref FLASHWINFO pwfi); [DllImport("user32", CharSet = CharSet.Auto)] public unsafe static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, Point* pptDst, Size* psize, IntPtr hdcSrc, Point* pprSrc, int crKey, BLENDFUNCTION* pblend, int dwFlags); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, SWP uFlags); [DllImport("user32")] public static extern IntPtr SetTimer(IntPtr hWnd, IntPtr nIDEvent, uint uElapse, IntPtr lpTimerFunc); [DllImport("user32")] public static extern bool KillTimer(IntPtr hWnd, IntPtr uIDEvent); [DllImport("user32")] public static extern bool HideCaret(IntPtr hwnd); [DllImport("user32")] public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); [DllImport("user32")] public static extern bool TrackPopupMenu(IntPtr hMenu, uint uFlags, int x, int y, int nReserved, IntPtr hWnd, IntPtr prcRect); [DllImport("user32", CharSet = CharSet.Auto)] public unsafe static extern bool InsertMenuItem(IntPtr hMenu, int uItem, bool fByPosition, MENUITEMINFO* lpmii); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public unsafe static extern bool GetMenuItemInfo(IntPtr hMenu, int uItem, bool fByPosition, MENUITEMINFO* lpmii); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public unsafe static extern bool SetMenuItemInfo(IntPtr hMenu, int uItem, bool fByPosition, MENUITEMINFO* lpmii); [DllImport("user32")] public static extern bool RemoveMenu(IntPtr hMenu, int uPosition, int uFlags); [DllImport("user32")] public static extern int GetWindowLong(IntPtr hWnd, GWL nIndex); [DllImport("user32")] public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, GWL nIndex); [DllImport("user32")] public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, GWL nIndex, IntPtr dwNewLong); [DllImport("user32")] public static extern IntPtr CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hwnd, WM Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32")] public static extern int SetWindowLong(IntPtr hWnd, GWL nIndex, int dwNewLong); [DllImport("user32")] public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, LWA dwFlags); [DllImport("user32", SetLastError = true)] public static extern bool GetLayeredWindowAttributes(IntPtr hwnd, out uint pcrKey, out byte pbAlpha, out LWA pdwFlags); [DllImport("user32")] public static extern bool AnimateWindow(IntPtr hwnd, uint dwTime, AW dwFlags); [DllImport("user32", CharSet = CharSet.Auto)] public static extern bool ShutdownBlockReasonCreate(IntPtr hWnd, string pwszReason); [DllImport("user32")] public static extern bool ShutdownBlockReasonDestroy(IntPtr hWnd); [DllImport("user32", CharSet = CharSet.Auto)] public static extern int GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT placement); [DllImport("user32")] public static extern IntPtr MonitorFromWindow(IntPtr hwnd, int dwFlags); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SetWindowsHookEx(WH idHook, HOOKPROC lpfn, IntPtr hMod, uint dwThreadId); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool UnhookWindowsHookEx(IntPtr hhk); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SetWinEventHook(EVENT eventMin, EVENT eventMax, IntPtr hmodWinEventProc, WINEVENTPROC pfnWinEventProc, int idProcess, uint idThread, WINEVENT dwFlags); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool UnhookWinEvent(IntPtr hWinEventHook); [DllImport("user32.dll", SetLastError = true)] public static extern bool GetWindowDisplayAffinity(IntPtr hWnd, out WDA dwAffinity); [DllImport("user32.dll", SetLastError = true)] public static extern bool SetWindowDisplayAffinity(IntPtr hWnd, WDA dwAffinity); [DllImport("user32", SetLastError = true)] public static extern bool SystemParametersInfo(SPI uiAction, int uiParam, string pvParam, SPIF fWinIni); [DllImport("user32", SetLastError = true)] public static extern bool SystemParametersInfo(SPI uiAction, int uiParam, StringBuilder pvParam, SPIF fWinIni); [DllImport("user32", SetLastError = true)] public static extern bool SystemParametersInfo(SPI uiAction, int uiParam, ref RECT pvParam, SPIF fWinIni); [DllImport("user32", SetLastError = true)] public static extern bool SystemParametersInfo(SPI uiAction, int uiParam, ref MINIMIZEDMETRICS pvParam, SPIF fWinIni); [DllImport("advapi32", SetLastError = true)] public static extern IntPtr OpenSCManager(string lpMachineName, string lpSCDB, int scParameter); [DllImport("advapi32", SetLastError = true)] public static extern IntPtr CreateService(IntPtr SC_HANDLE, string lpSvcName, string lpDisplayName, int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl, string lpPathName, string lpLoadOrderGroup, IntPtr lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword); [DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool ChangeServiceConfig(IntPtr hService, int nServiceType, int nStartType, int nErrorControl, string lpBinaryPathName, string lpLoadOrderGroup, IntPtr lpdwTagId, string lpDependencies, string lpServiceStartName, string lpPassword, string lpDisplayName); [DllImport("advapi32", CharSet = CharSet.Unicode, SetLastError = true)] public static extern bool ChangeServiceConfig2(IntPtr hService, int dwInfoLevel, ref bool lpInfo); [DllImport("advapi32", SetLastError = true)] public static extern bool CloseServiceHandle(IntPtr hService); [DllImport("advapi32", SetLastError = true)] public static extern bool DeleteService(IntPtr hService); [DllImport("advapi32", SetLastError = true)] public static extern IntPtr OpenService(IntPtr hService, string lpSvcName, int dwNumServiceArgs); [DllImport("advapi32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool StartService(IntPtr hService, int dwNumServiceArgs, string[] lpServiceArgVectors); [DllImport("advapi32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool ControlService(IntPtr hService, SERVICE_CONTROL dwControl, ref SERVICE_STATUS lpServiceStatus); [DllImport("advapi32")] public static extern bool QueryServiceStatus(IntPtr hService, ref SERVICE_STATUS dwServiceStatus); [DllImport("kernel32", SetLastError = true)] public static extern bool SetProcessShutdownParameters(uint level, uint flags); [DllImport("user32", SetLastError = true)] public static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason); [DllImport("advapi32", SetLastError = true)] public static extern bool CreateWellKnownSid(WellKnownSidType WellKnownSidType, IntPtr DomainSid, IntPtr pSid, ref uint cbSid); [DllImport("advapi32", SetLastError = true)] public static extern bool CheckTokenMembership(IntPtr TokenHandle, IntPtr SidToCheck, out bool IsMember); [DllImport("kernel32", SetLastError = true)] public static extern IntPtr GetCurrentProcess(); [DllImport("kernel32", SetLastError = true)] public static extern int GetCurrentProcessId(); [DllImport("kernel32", SetLastError = true)] public static extern int GetTempPath2(int BufferLength, [Out] StringBuilder Buffer); [DllImport("advapi32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool OpenProcessToken(IntPtr ProcessHandle, TOKEN DesiredAccess, out IntPtr TokenHandle); [DllImport("advapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool DuplicateTokenEx(IntPtr hExistingToken, TOKEN dwDesiredAccess, IntPtr lpTokenAttributes, SECURITY_IMPERSONATION_LEVEL ImpersonationLevel, TOKEN_TYPE TokenType, out IntPtr phNewToken); [DllImport("kernel32", SetLastError = true)] public static extern bool DuplicateHandle(IntPtr hSourceProcessHandle, IntPtr hSourceHandle, IntPtr hTargetProcessHandle, out IntPtr lpTargetHandle, uint dwDesiredAccess, bool bInheritHandle, uint dwOptions); [DllImport("advapi32", CharSet = CharSet.Auto, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, out LUID lpLuid); [DllImport("advapi32", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool AdjustTokenPrivileges(IntPtr TokenHandle, [MarshalAs(UnmanagedType.Bool)] bool DisableAllPrivileges, ref TOKEN_PRIVILEGES NewState, uint BufferLength, IntPtr PreviousState, IntPtr ReturnLength); [DllImport("user32", SetLastError = true)] public static extern bool AddClipboardFormatListener(IntPtr hwnd); [DllImport("user32", SetLastError = true)] public static extern bool RemoveClipboardFormatListener(IntPtr hwnd); [DllImport("user32", SetLastError = true)] public static extern IntPtr SetClipboardViewer(IntPtr hWndNewViewer); [DllImport("user32", SetLastError = true)] public static extern bool ChangeClipboardChain(IntPtr hWndRemove, IntPtr hWndNewNext); [DllImport("user32", SetLastError = true)] public static extern bool OpenClipboard(IntPtr hWndNewOwner); [DllImport("user32", SetLastError = true)] public static extern bool CloseClipboard(); [DllImport("user32", SetLastError = true)] public static extern bool EmptyClipboard(); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetClipboardOwner(); [DllImport("user32", SetLastError = true)] public static extern IntPtr SetClipboardData(int uFormat, IntPtr hMem); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetClipboardData(uint uFormat); [DllImport("user32", SetLastError = true)] public static extern bool IsClipboardFormatAvailable(uint format); [DllImport("user32", SetLastError = true)] public static extern uint RegisterClipboardFormat(string lpszFormat); [DllImport("ole32", PreserveSig = false)] public static extern IDataObject OleGetClipboard(); [DllImport("ole32", PreserveSig = false)] public static extern void OleSetClipboard(IDataObject pDataObj); [DllImport("kernel32", SetLastError = true)] public static extern int WTSGetActiveConsoleSessionId(); [DllImport("wtsapi32", SetLastError = true)] public static extern bool WTSQueryUserToken(int SessionId, out IntPtr phToken); [DllImport("wtsapi32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool WTSQuerySessionInformation(IntPtr hServer, int sessionId, WTS_INFO_CLASS wtsInfoClass, out IntPtr ppBuffer, out uint pBytesReturned); [DllImport("wtsapi32", CharSet = CharSet.Auto, SetLastError = true)] public unsafe static extern bool WTSEnumerateSessions(IntPtr hServer, int Reserved, int Version, WTS_SESSION_INFO** ppSessionInfo, int* pCount); [DllImport("wtsapi32", SetLastError = true)] public static extern bool WTSDisconnectSession(IntPtr hServer, int SessionId, bool bWait); [DllImport("wtsapi32", SetLastError = true)] public static extern bool WTSLogoffSession(IntPtr hServer, int SessionId, bool bWait); [DllImport("wtsapi32")] public static extern void WTSFreeMemory(IntPtr pMemory); [DllImport("Ole32")] public static extern void PropVariantClear(ref PROPVARIANT pvar); [DllImport("winmm", SetLastError = true)] public static extern int waveOutOpen(out IntPtr phwo, int uDeviceID, IntPtr pwfx, IntPtr dwCallback, IntPtr dwCallbackInstance, int fdwOpen); [DllImport("winmm", SetLastError = true)] public unsafe static extern int waveOutPrepareHeader(IntPtr hWaveOut, WAVEHDR* pwh, int cbwh); [DllImport("winmm", SetLastError = true)] public unsafe static extern int waveOutWrite(IntPtr hwo, WAVEHDR* pwh, int cbwh); [DllImport("winmm", SetLastError = true)] public unsafe static extern int waveOutUnprepareHeader(IntPtr hwo, WAVEHDR* pwh, int cbwh); [DllImport("winmm", SetLastError = true)] public static extern int waveOutClose(IntPtr hwo); [DllImport("winmm", SetLastError = true)] public static extern int waveOutPause(IntPtr hwo); [DllImport("winmm", SetLastError = true)] public static extern int waveOutReset(IntPtr hwo); [DllImport("winmm", SetLastError = true)] public static extern int waveOutRestart(IntPtr hwo); [DllImport("winmm", SetLastError = true)] public static extern int waveOutGetPosition(IntPtr hwo, ref MMTIME pmmt, int cbmmt); [DllImport("winmm", SetLastError = true)] public static extern uint waveOutGetNumDevs(); [DllImport("winmm", CharSet = CharSet.Unicode, SetLastError = true)] public unsafe static extern int waveOutGetDevCaps(uint uDeviceID, void* pwoc, uint cbwoc); [DllImport("winmm", SetLastError = true)] public static extern int waveOutSetVolume(IntPtr hwo, int dwVolume); [DllImport("winmm")] public static extern int waveInOpen(out IntPtr phwi, int uDeviceID, IntPtr pwfx, IntPtr dwCallback, IntPtr dwCallbackInstance, int fdwOpen); [DllImport("winmm", SetLastError = true)] public static extern int waveInStart(IntPtr hwi); [DllImport("winmm", SetLastError = true)] public static extern int waveInStop(IntPtr hwi); [DllImport("winmm", SetLastError = true)] public unsafe static extern int waveInPrepareHeader(IntPtr hwi, WAVEHDR* pwh, int cbwh); [DllImport("winmm", SetLastError = true)] public unsafe static extern int waveInUnprepareHeader(IntPtr hwi, WAVEHDR* pwh, int cbwh); [DllImport("winmm", SetLastError = true)] public static extern int waveInClose(IntPtr hwi); [DllImport("winmm", SetLastError = true)] public unsafe static extern int waveInAddBuffer(IntPtr hwi, WAVEHDR* pwh, int cbwh); [DllImport("winmm", SetLastError = true)] public static extern uint waveInGetNumDevs(); [DllImport("winmm", CharSet = CharSet.Unicode, SetLastError = true)] public unsafe static extern int waveInGetDevCaps(uint uDeviceID, void* pwic, uint cbwic); [DllImport("winmm", SetLastError = true)] public unsafe static extern int waveInGetID(IntPtr hwi, uint* puDeviceID); [DllImport("msdmo", PreserveSig = false)] public static extern void MoInitMediaType(ref DMO_MEDIA_TYPE pmt, int cbFormat); [DllImport("msdmo", PreserveSig = false)] public static extern void MoFreeMediaType(ref DMO_MEDIA_TYPE pmt); [DllImport("user32", SetLastError = true)] public static extern bool RegisterShellHookWindow(IntPtr hwnd); [DllImport("user32", SetLastError = true)] public static extern bool SetTaskmanWindow(IntPtr hwnd); [DllImport("user32", SetLastError = true)] public static extern bool SetShellWindow(IntPtr hwnd); [DllImport("user32", SetLastError = true)] public static extern bool SetShellChangeNotifyWindow(IntPtr hwnd); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetShellChangeNotifyWindow(); [DllImport("shell32", EntryPoint = "#938", SetLastError = true)] public static extern IntPtr SCNSystemInitialize_FromReverseEngineering(); [DllImport("shell32")] public unsafe static extern uint SHChangeNotifyRegister(IntPtr hwnd, int fSources, int fEvents, int wMsg, int cEntries, SHChangeNotifyEntry* pshcne); [DllImport("shell32")] public static extern bool SHChangeNotifyDeregister(uint ulID); [DllImport("shell32", SetLastError = true)] public static extern IntPtr CommandLineToArgvW([MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs); [DllImport("shell32", PreserveSig = false)] public static extern IShellFolder SHGetDesktopFolder(); [DllImport("shell32", PreserveSig = false)] public static extern IntPtr SHBindToParent(IntPtr pidl, [MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppv); [DllImport("shell32")] public static extern int SHGetFolderPath(IntPtr hwndOwner, Environment.SpecialFolder nFolder, IntPtr hToken, uint dwFlags, [Out] StringBuilder pszPath); [DllImport("shell32", CharSet = CharSet.Auto)] public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, int cbSizeFileInfo, SHGFI uFlags); [DllImport("shell32")] public static extern bool Shell_GetImageLists(out IntPtr phiml, out IntPtr phimlSmall); [DllImport("comctl32", CharSet = CharSet.Auto)] public static extern IntPtr ImageList_GetIcon(IntPtr himl, int i, int flags); [DllImport("shell32", EntryPoint = "#74")] public static extern int SHCreateStdEnumFmtEtc(uint cfmt, FORMATETC[] afmt, out IEnumFORMATETC ppenumFormatEtc); [DllImport("shell32", PreserveSig = false)] public static extern void SHOpenFolderAndSelectItems(IntPtr pidlFolder, int cidl, IntPtr[] apidl, int dwFlags); [DllImport("shell32", CharSet = CharSet.Auto)] public static extern IntPtr ILCreateFromPath(string pszPath); [DllImport("shell32")] public static extern void ILFree(IntPtr pidl); [DllImport("shell32", PreserveSig = false)] [return: MarshalAs(UnmanagedType.Interface)] public static extern object SHCreateItemFromIDList(IntPtr pidl, [MarshalAs(UnmanagedType.LPStruct)] Guid riid); [DllImport("winmm.dll", CharSet = CharSet.Auto)] public static extern int mmioStringToFOURCC([MarshalAs(UnmanagedType.LPTStr)] string sz, int uFlags); [DllImport("avifil32")] public static extern int AVIFileOpen(out IntPtr ppfile, string szFile, uint mode, int pclsidHandler); [DllImport("avifil32")] public static extern int AVIFileRelease(IntPtr pfile); [DllImport("avifil32")] public static extern int AVIFileCreateStream(IntPtr pfile, out IntPtr ppavi, ref AVISTREAMINFO ptr_streaminfo); [DllImport("avifil32")] public static extern int AVIStreamRelease(IntPtr pavi); [DllImport("avifil32")] public static extern int AVIStreamSetFormat(IntPtr pavi, int lPos, ref BITMAPINFO lpFormat, int cbFormat); [DllImport("avifil32")] public static extern int AVIStreamWrite(IntPtr pavi, int lStart, int lSamples, IntPtr lpBuffer, int cbBuffer, int dwFlags, IntPtr plSampWritten, IntPtr plBytesWritten); [DllImport("avifil32")] public static extern void AVIFileInit(); [DllImport("avifil32")] public static extern void AVIFileExit(); [DllImport("avifil32")] public static extern int AVIMakeCompressedStream(out IntPtr ppsCompressed, IntPtr psSource, ref AVICOMPRESSOPTIONS lpOptions, IntPtr pclsidHandler); [DllImport("kernel32")] public static extern bool AllocConsole(); [DllImport("kernel32")] public static extern bool FreeConsole(); [DllImport("kernel32")] public static extern bool SetConsoleOutputCP(int codepageID); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr GetModuleHandle(string lpModuleName); [DllImport("kernel32", SetLastError = true)] public static extern uint GetCurrentThreadId(); [DllImport("user32", SetLastError = true)] public static extern IntPtr OpenWindowStation(string lpszWinSta, bool fInherit, ACCESS_MASK dwDesiredAccess); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetProcessWindowStation(); [DllImport("user32", SetLastError = true)] public static extern bool SetProcessWindowStation(IntPtr hWinSta); [DllImport("user32", SetLastError = true)] public static extern bool CloseWindowStation(IntPtr hWinSta); [DllImport("user32", SetLastError = true)] public static extern IntPtr GetThreadDesktop(uint dwThreadId); [DllImport("user32", SetLastError = true)] public static extern bool SetThreadDesktop(IntPtr hDesktop); [DllImport("kernel32", SetLastError = true)] public static extern bool CloseHandle(IntPtr hObject); [DllImport("user32", SetLastError = true)] public static extern IntPtr ChangeWindowMessageFilter(int message, uint dwFlag); [DllImport("user32", CharSet = CharSet.Auto, SetLastError = true)] public static extern int RegisterWindowMessage(string lpString); [DllImport("kernel32")] public static extern bool SetProcessAffinityMask(IntPtr hProcess, ulong dwProcessAffinityMask); [DllImport("kernel32")] public static extern bool GetProcessAffinityMask(IntPtr hProcess, out ulong lpProcessAffinityMask, out ulong lpSystemAffinityMask); [DllImport("kernel32")] public static extern IntPtr GlobalLock(IntPtr hMem); [DllImport("kernel32")] public static extern bool GlobalUnlock(IntPtr hMem); [DllImport("kernel32", SetLastError = true)] public static extern IntPtr LoadLibrary(string lpFileName); [DllImport("kernel32", SetLastError = true)] public unsafe static extern IntPtr LoadLibrary(void* lpFileName); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern SafeLibraryHandle LoadLibraryEx(string lpFileName, IntPtr hFile, LOAD_LIBRARY_FLAGS dwFlags); [DllImport("kernel32", SetLastError = true)] public static extern bool FreeLibrary(IntPtr hModule); [DllImport("kernel32", CharSet = CharSet.Ansi)] public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); [DllImport("kernel32")] public unsafe static extern IntPtr GetProcAddress(IntPtr hModule, void* lpProcName); [DllImport("kernel32", SetLastError = true)] public static extern bool SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH DirectoryFlags); [DllImport("kernel32", SetLastError = true)] public static extern bool SetProcessMitigationPolicy(PROCESS_MITIGATION_POLICY MitigationPolicy, ref int lpBuffer, IntPtr dwLength); [DllImport("kernel32", CharSet = CharSet.Unicode)] public static extern uint GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName); [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFileName); [DllImport("user32", SetLastError = true)] public static extern bool SetProcessDPIAware(); [DllImport("user32", SetLastError = true)] public static extern bool SetProcessDpiAwarenessInternal(int value); [DllImport("wmsgapi")] public static extern uint WmsgSendMessage(int dwSessionId, int magicNumber, IntPtr pid, IntPtr lParam); [DllImport("sas")] public static extern void SendSAS(bool AsUser); [DllImport("kernel32")] public static extern IntPtr LocalAlloc(uint uFlags, UIntPtr uBytes); [DllImport("kernel32")] public static extern IntPtr LocalFree(IntPtr hMem); [DllImport("dwmapi")] public static extern int DwmSetWindowAttribute(IntPtr hwnd, int dwAttribute, ref int pvAttribute, int cbAttribute); [DllImport("dwmapi")] public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, ref RECT pvAttribute, int cbAttribute); [DllImport("dwmapi", PreserveSig = false)] public static extern int DwmEnableComposition(bool fEnable); [DllImport("dwmapi")] public static extern int DwmIsCompositionEnabled(out bool enabled); [DllImport("dwmapi")] public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins); [DllImport("ole32")] public static extern void ReleaseStgMedium(ref STGMEDIUM pmedium); [DllImport("kernel32")] public static extern void GetSystemTimeAsFileTime(out long lpSystemTimeAsFileTime); [DllImport("user32")] public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); [DllImport("kernel32")] public static extern uint GetTickCount(); [DllImport("kernel32")] public static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer); [DllImport("netapi32", CharSet = CharSet.Auto)] public static extern int NetGetJoinInformation(IntPtr lpServer, out IntPtr lpNameBuffer, out int BufferType); [DllImport("netapi32", CharSet = CharSet.Auto)] public static extern int NetApiBufferFree(IntPtr Buffer); [DllImport("urlmon")] public static extern int UrlMkSetSessionOption(int dwOption, string pBuffer, int dwBufferLength, int dwReserved); [DllImport("kernel32", SetLastError = true)] public unsafe static extern byte* VirtualAlloc(void* lpAddress, IntPtr dwSize, MEM flAllocationType, PAGE flProtect); [DllImport("kernel32")] public unsafe static extern bool VirtualFree(void* lpAddress, IntPtr dwSize, MEM dwFreeType); [DllImport("kernel32")] public unsafe static extern bool VirtualProtect(void* lpAddress, IntPtr dwSize, PAGE flNewProtect, PAGE* lpflOldProtect); [DllImport("ntdll", CharSet = CharSet.Ansi)] public unsafe static extern int RtlGetVersion(OSVERSIONINFOEX* lpVersionInformation); [DllImport("kernel32", SetLastError = true)] public static extern void GetSystemInfo(ref SYSTEM_INFO Info); [DllImport("kernel32", SetLastError = true)] public static extern void EnterCriticalSection(IntPtr lpCriticalSection); [DllImport("kernel32", SetLastError = true)] public static extern void LeaveCriticalSection(IntPtr lpCriticalSection); [DllImport("ole32", PreserveSig = false)] [return: MarshalAs(UnmanagedType.Interface)] public static extern object CoGetClassObject([In][MarshalAs(UnmanagedType.LPStruct)] Guid rclsid, int dwClsContext, IntPtr pServerInfo, [In][MarshalAs(UnmanagedType.LPStruct)] Guid riid); [DllImport("ole32", PreserveSig = false)] public static extern IStream CreateStreamOnHGlobal(IntPtr hGlobal, bool fDeleteOnRelease); [DllImport("advapi32", CharSet = CharSet.Auto)] public static extern int RegCreateKeyEx(IntPtr hKey, string lpSubKey, int Reserved, string lpClass, int dwOptions, int samDesired, IntPtr lpSecurityAttributes, out IntPtr phkResult, out int lpdwDisposition); [DllImport("advapi32", CharSet = CharSet.Auto)] public static extern int RegOpenKeyEx(IntPtr hKey, string lpSubKey, int ulOptions, int samDesired, out IntPtr phkResult); [DllImport("advapi32")] public static extern int RegCloseKey(IntPtr hKey); [DllImport("advapi32", CharSet = CharSet.Auto)] public static extern int RegDeleteKeyValue(IntPtr hKey, string lpSubKey, string lpValueName); [DllImport("advapi32", CharSet = CharSet.Auto)] public static extern int RegQueryValueEx(IntPtr hKey, string lpValueName, int lpReserved, out RegistryValueKind lpType, StringBuilder lpData, ref uint lpcbData); [DllImport("advapi32", CharSet = CharSet.Auto)] public static extern int RegSetValueEx(IntPtr hKey, string lpValueName, int Reserved, RegistryValueKind dwType, IntPtr lpData, int cbData); [DllImport("advapi32")] public static extern int RegDisablePredefinedCache(); [DllImport("kernel32", SetLastError = true)] public static extern bool CancelSynchronousIo(SafeFileHandle hThread); [DllImport("kernel32", SetLastError = true)] public static extern SafeFileHandle OpenThread(int dwDesiredAccess, bool bInheritHandle, uint dwThreadId); [DllImport("kernel32", SetLastError = true)] public static extern bool Wow64DisableWow64FsRedirection(ref IntPtr ptr); [DllImport("kernel32", SetLastError = true)] public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr); [DllImport("kernel32", SetLastError = true)] public unsafe static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public unsafe static extern SafeFileHandle CreateNamedPipe(string lpName, PIPE_ACCESS dwOpenMode, PIPE_MODE dwPipeMode, int nMaxInstances, int nOutBufferSize, int nInBufferSize, int nDefaultTimeOut, SECURITY_ATTRIBUTES* lpSecurityAttributes); [DllImport("kernel32", SetLastError = true)] public static extern bool DisconnectNamedPipe(SafeFileHandle hNamedPipe); [DllImport("kernel32", SetLastError = true)] public unsafe static extern bool ConnectNamedPipe(SafeFileHandle hNamedPipe, NativeOverlapped* lpOverlapped); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool WaitNamedPipe(string lpNamedPipeName, int nTimeOut); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool DeleteFile(string lpFileName); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool MoveFileEx(string lpExistingFileName, string lpNewFileName, MOVEFILE dwFlags); [DllImport("ktmw32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr CreateTransaction(IntPtr lpTransactionAttributes, IntPtr UOW, int CreateOptions, int IsolationLevel, int IsolationFlags, int Timeout, string Description); [DllImport("ktmw32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool CommitTransaction(IntPtr TransactionHandle); [DllImport("ktmw32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool RollbackTransaction(IntPtr TransactionHandle); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool MoveFileTransacted(string lpExistingFileName, string lpNewFileName, IntPtr lpProgressRoutine, IntPtr lpData, MOVEFILE dwFlags, IntPtr hTransaction); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool CreateSymbolicLinkTransacted(string lpSymlinkFileName, string lpTargetFileName, int dwFlags, IntPtr hTransaction); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool DeleteFileTransacted(string lpFileName, IntPtr hTransaction); [DllImport("kernel32")] public static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags); [DllImport("kernel32")] public unsafe static extern bool DeviceIoControl(SafeHandle hDevice, int dwIoControlCode, void* lpInBuffer, int nInBufferSize, void* lpOutBuffer, int nOutBufferSize, int* lpBytesReturned, IntPtr lpOverlapped); [DllImport("oleacc", PreserveSig = false)] [return: MarshalAs(UnmanagedType.IUnknown)] public static extern object AccessibleObjectFromWindow(IntPtr hwnd, int dwObjectID, [MarshalAs(UnmanagedType.LPStruct)] Guid riid); [DllImport("oleacc")] public static extern uint AccessibleChildren(IAccessible paccContainer, int iChildStart, int cChildren, [In][Out][MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] object[] rgvarChildren, out int pcObtained); [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool OpenPrinter(string szPrinter, out IntPtr hPrinter, ref PRINTER_DEFAULTS pd); [DllImport("winspool.drv", SetLastError = true)] public static extern bool ClosePrinter(IntPtr hPrinter); [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)] public static extern int StartDocPrinter(IntPtr hPrinter, int level, ref DOC_INFO_3 di); [DllImport("winspool.drv", SetLastError = true)] public static extern bool EndDocPrinter(IntPtr hPrinter); [DllImport("winspool.drv", SetLastError = true)] public static extern bool StartPagePrinter(IntPtr hPrinter); [DllImport("winspool.drv", SetLastError = true)] public static extern bool EndPagePrinter(IntPtr hPrinter); [DllImport("winspool.drv", PreserveSig = false, SetLastError = true)] public unsafe static extern int WritePrinter(IntPtr hPrinter, byte* pBytes, int dwCount); [DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)] public unsafe static extern bool GetPrinterDriver(IntPtr hPrinter, IntPtr pEnvironment, int Level, byte* pDriverInfo, int cbBuf, out int pcbNeeded); [DllImport("xpsprint", CharSet = CharSet.Auto, PreserveSig = false)] public static extern void StartXpsPrintJob(string printerName, string jobName, string outputFileName, SafeWaitHandle progressEvent, SafeWaitHandle completionEvent, IntPtr printablePagesOn, uint printablePagesOnCount, out IXpsPrintJob xpsPrintJob, out IXpsPrintJobStream documentStream, IntPtr printTicketStream); [DllImport("magnification", SetLastError = true)] public static extern bool MagInitialize(); [DllImport("magnification", SetLastError = true)] public static extern bool MagUninitialize(); [DllImport("magnification", SetLastError = true)] public static extern bool MagSetWindowSource(IntPtr hwnd, RECT rect); [DllImport("magnification", SetLastError = true)] public static extern bool MagSetWindowFilterList(IntPtr hwnd, int dwFilterMode, int count, IntPtr[] pHWND); [DllImport("magnification", SetLastError = true)] public static extern bool MagSetImageScalingCallback(IntPtr hwnd, MagImageScalingCallback callback); [DllImport("User32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool EnumDisplaySettings(string lpszDeviceName, [MarshalAs(UnmanagedType.U4)] int iModeNum, [In][Out] ref DevMode lpDevMode); [DllImport("user32.dll")] public static extern DISP_CHANGE ChangeDisplaySettingsEx(string lpszDeviceName, ref DevMode lpDevMode, IntPtr hwnd, ChangeDisplaySettingsFlags dwflags, IntPtr lParam); [DllImport("user32.dll")] public static extern DISP_CHANGE ChangeDisplaySettingsEx(string lpszDeviceName, IntPtr lpDevMode, IntPtr hwnd, ChangeDisplaySettingsFlags dwflags, IntPtr lParam); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern SafeResourceUpdateHandle BeginUpdateResource(string fileName, bool deleteExistingResource); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool UpdateResource(SafeResourceUpdateHandle hUpdate, IntPtr lpType, string lpName, short wLanguage, byte[] data, int cbData); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool UpdateResource(SafeResourceUpdateHandle hUpdate, string lpType, string lpName, short wLanguage, byte[] data, int cbData); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr FindResource(SafeLibraryHandle hModule, string lpName, IntPtr lpType); [DllImport("kernel32", SetLastError = true)] public static extern IntPtr LoadResource(SafeLibraryHandle hModule, IntPtr hResInfo); [DllImport("kernel32")] public static extern IntPtr LockResource(IntPtr hResInfo); [DllImport("kernel32", SetLastError = true)] public static extern uint SizeofResource(SafeLibraryHandle hModule, IntPtr hResInfo); [DllImport("Kernel32")] public static extern bool GetProductInfo(int dwOSMajorVersion, int dwOSMinorVersion, int dwSpMajorVersion, int dwSpMinorVersion, out PRODUCT pdwReturnedProductType); }