Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace SecureDesktop
- {
- public class WinAPI
- {
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool GetExitCodeProcess(IntPtr hProcess, out uint lpExitCode);
- [DllImport("user32.dll")]
- public static extern IntPtr CreateDesktop(string lpszDesktop, IntPtr lpszDevice,
- IntPtr pDevmode, int dwFlags, uint dwDesiredAccess, IntPtr lpsa);
- [DllImport("user32.dll")]
- public static extern bool SwitchDesktop(IntPtr hDesktop);
- [DllImport("user32.dll")]
- public static extern bool CloseDesktop(IntPtr handle);
- [DllImport("user32.dll")]
- public static extern bool SetThreadDesktop(IntPtr hDesktop);
- [DllImport("user32.dll")]
- public static extern IntPtr GetThreadDesktop(int dwThreadId);
- [DllImport("kernel32.dll")]
- public static extern int GetCurrentThreadId();
- [DllImport("kernel32.dll", SetLastError = true)]
- public static extern bool CreateProcess(
- string lpApplicationName, string lpCommandLine, IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, bool bInheritHandles,
- uint dwCreationFlags, IntPtr lpEnvironment, string lpCurrentDirectory, ref STARTUPINFO lpStartupInfo,
- out PROCESS_INFORMATION lpProcessInformation);
- [DllImport("kernel32.dll", SetLastError = true)]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool TerminateProcess(IntPtr hProcess, uint uExitCode);
- public enum DESKTOP_ACCESS : uint
- {
- DESKTOP_NONE = 0,
- DESKTOP_READOBJECTS = 0x0001,
- DESKTOP_CREATEWINDOW = 0x0002,
- DESKTOP_CREATEMENU = 0x0004,
- DESKTOP_HOOKCONTROL = 0x0008,
- DESKTOP_JOURNALRECORD = 0x0010,
- DESKTOP_JOURNALPLAYBACK = 0x0020,
- DESKTOP_ENUMERATE = 0x0040,
- DESKTOP_WRITEOBJECTS = 0x0080,
- DESKTOP_SWITCHDESKTOP = 0x0100,
- GENERIC_ALL = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU |
- DESKTOP_HOOKCONTROL | DESKTOP_JOURNALRECORD | DESKTOP_JOURNALPLAYBACK |
- DESKTOP_ENUMERATE | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP),
- #if HOOKS_ENABLED
- CUSTOM_SECURE = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | DESKTOP_HOOKCONTROL | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP)
- #else
- CUSTOM_SECURE = (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU | DESKTOP_WRITEOBJECTS | DESKTOP_SWITCHDESKTOP)
- #endif
- }
- public struct PROCESS_INFORMATION
- {
- public IntPtr hProcess;
- public IntPtr hThread;
- public uint dwProcessId;
- public uint dwThreadId;
- }
- public struct STARTUPINFO
- {
- public uint cb;
- public string lpReserved;
- public string lpDesktop;
- public string lpTitle;
- public uint dwX;
- public uint dwY;
- public uint dwXSize;
- public uint dwYSize;
- public uint dwXCountChars;
- public uint dwYCountChars;
- public uint dwFillAttribute;
- public uint dwFlags;
- public short wShowWindow;
- public short cbReserved2;
- public IntPtr lpReserved2;
- public IntPtr hStdInput;
- public IntPtr hStdOutput;
- public IntPtr hStdError;
- }
- public const int
- ULW_ALPHA = 0x00000002,
- WS_EX_LAYERED = 0x00080000,
- WS_EX_TRANSPARENT = 0x00000020,
- WS_EX_TOOLWINDOW = 0x00000080,
- WS_EX_TOPMOST = 0x00000008;
- public const byte AC_SRC_OVER = 0x00;
- public const byte AC_SRC_ALPHA = 0x01;
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
- struct ARGB
- {
- public byte Blue;
- public byte Green;
- public byte Red;
- public byte Alpha;
- }
- [StructLayout(LayoutKind.Sequential, Pack = 1)]
- public struct BLENDFUNCTION
- {
- public byte BlendOp;
- public byte BlendFlags;
- public byte SourceConstantAlpha;
- public byte AlphaFormat;
- }
- [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
- public static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
- [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
- public static extern IntPtr GetDC(IntPtr hWnd);
- [DllImport("user32.dll", ExactSpelling = true)]
- public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
- [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
- public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
- [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
- public static extern bool DeleteDC(IntPtr hdc);
- [DllImport("gdi32.dll", ExactSpelling = true)]
- public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
- [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)]
- public static extern bool DeleteObject(IntPtr hObject);
- public static IntPtr HWND_TOPMOST = new IntPtr(-1);
- public const int
- SWP_NOSIZE = 0x0001,
- SWP_NOMOVE = 0x0002,
- SWP_SHOWWINDOW = 0x0040;
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
- public enum ShowCommands : int
- {
- SW_HIDE = 0,
- SW_SHOWNORMAL = 1,
- SW_NORMAL = 1,
- SW_SHOWMINIMIZED = 2,
- SW_SHOWMAXIMIZED = 3,
- SW_MAXIMIZE = 3,
- SW_SHOWNOACTIVATE = 4,
- SW_SHOW = 5,
- SW_MINIMIZE = 6,
- SW_SHOWMINNOACTIVE = 7,
- SW_SHOWNA = 8,
- SW_RESTORE = 9,
- SW_SHOWDEFAULT = 10,
- SW_FORCEMINIMIZE = 11,
- SW_MAX = 11
- }
- [DllImport("shell32.dll")]
- public static extern IntPtr ShellExecute(
- IntPtr hwnd,
- string lpOperation,
- string lpFile,
- string lpParameters,
- string lpDirectory,
- ShowCommands nShowCmd);
- [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder pszOut, ref uint pcchOut);
- [Flags]
- public enum AssocF : uint
- {
- None = 0,
- Init_NoRemapCLSID = 0x1,
- Init_ByExeName = 0x2,
- Open_ByExeName = 0x2,
- Init_DefaultToStar = 0x4,
- Init_DefaultToFolder = 0x8,
- NoUserSettings = 0x10,
- NoTruncate = 0x20,
- Verify = 0x40,
- RemapRunDll = 0x80,
- NoFixUps = 0x100,
- IgnoreBaseClass = 0x200,
- Init_IgnoreUnknown = 0x400,
- Init_FixedProgId = 0x800,
- IsProtocol = 0x1000,
- InitForFile = 0x2000,
- }
- public enum AssocStr
- {
- Command = 1,
- Executable,
- FriendlyDocName,
- FriendlyAppName,
- NoOpen,
- ShellNewValue,
- DDECommand,
- DDEIfExec,
- DDEApplication,
- DDETopic,
- InfoTip,
- QuickTip,
- TileInfo,
- ContentType,
- DefaultIcon,
- ShellExtension,
- DropTarget,
- DelegateExecute,
- SupportedUriProtocols,
- Max,
- }
- public const int S_OK = 0, S_FALSE = 1;
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
- public class MEMORYSTATUSEX
- {
- public uint dwLength;
- public uint dwMemoryLoad;
- public ulong ullTotalPhys;
- public ulong ullAvailPhys;
- public ulong ullTotalPageFile;
- public ulong ullAvailPageFile;
- public ulong ullTotalVirtual;
- public ulong ullAvailVirtual;
- public ulong ullAvailExtendedVirtual;
- public MEMORYSTATUSEX()
- {
- this.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
- }
- }
- [return: MarshalAs(UnmanagedType.Bool)]
- [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
- public static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
- [StructLayout(LayoutKind.Sequential)]
- public struct POINT
- {
- public int X;
- public int Y;
- }
- [DllImport("user32.dll")]
- public static extern bool GetCursorPos(out POINT lpPoint);
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern bool GetDiskFreeSpace(string lpRootPathName,
- out uint lpSectorsPerCluster,
- out uint lpBytesPerSector,
- out uint lpNumberOfFreeClusters,
- out uint lpTotalNumberOfClusters);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment