C # hidden processes in Task Manager

Source: Internet
Author: User

This is just to hide it in the WINDOWS Task Manager, not disappear in the process.

For example, if you want to hide the QQ process, it is not displayed in the WINDOWS Task Manager.

Usage

Private WindowsAPI. HideTaskmgrList _ List = new WindowsAPI. HideTaskmgrList ();
Private void Form1_Load (object sender, EventArgs e)
{
_ List. ProcessName = "QQ.exe ";
_ List. Star ();

}

Below are all classes

View plaincopy to clipboardprint?
Namespace WindowsAPI
{
/// <Summary>
/// Process is not displayed in WINDOWS Task Manager
/// Qq: 116149
// Zgke@sina.copm
/// </Summary>
Public class HideTaskmgrList
{
Private System. Timers. Timer m_Time = new System. Timers. Timer ();
Private string m_ProcessName = "";
Private int m_ProcessID = 0;

/// <Summary>
/// Process name
/// </Summary>
Public string ProcessName {get {return m_ProcessName;} set {m_ProcessName = value ;}}

/// <Summary>
/// Start
/// </Summary>
Public void Star ()
{
M_Time.Enabled = true;
}

/// <Summary>
/// Stop
/// </Summary>
Public void Stop ()
{
M_Time.Enabled = false;
}

Public HideTaskmgrList ()
{
M_Time.Interval = 1;
M_Time.Elapsed + = new System. Timers. ElapsedEventHandler (_ Time_Elapsed );
}

Void _ Time_Elapsed (object sender, System. Timers. ElapsedEventArgs e)
{
HideTaskmgrListOfName (m_ProcessName );
}

/// <Summary>
/// Obtain all controls
/// </Summary>
/// <Param name = "p_Handle"> </param>
/// <Param name = "p_Param"> </param>
/// <Returns> </returns>
Private bool NetEnumControl (IntPtr p_Handle, int p_Param)
{
WindowsAPI. Win32API. STRINGBUFFER _ TextString = new WindowsAPI. Win32API. STRINGBUFFER ();
WindowsAPI. Win32API. GetWindowText (p_Handle, out _ TextString, 256 );

WindowsAPI. Win32API. STRINGBUFFER _ ClassName = new WindowsAPI. Win32API. STRINGBUFFER ();
WindowsAPI. Win32API. GetClassName (p_Handle, out _ ClassName, 255 );

If (_ TextString. szText = "process" & _ ClassName. szText = "SysListView32 ")
{
Hide (p_Handle );
Return false;
}

Return true;
}

/// <Summary>
/// Hide
/// </Summary>
/// <Param name = "p_ListViewIntPtr"> </param>
Public void Hide (IntPtr p_ListViewIntPtr)
{
IntPtr _ ControlIntPtr = p_ListViewIntPtr;

Int _ ItemCount = WindowsAPI. Win32API. SendMessage (p_ListViewIntPtr, 0x1004, 0, 0 );

WindowsAPI. Win32API. ProcessAccessType _ Type;
_ Type = WindowsAPI. Win32API. ProcessAccessType. PROCESS_VM_OPERATION | WindowsAPI. Win32API. ProcessAccessType. PROCESS_VM_READ | WindowsAPI. Win32API. ProcessAccessType. PROCESS_VM_WRITE;

IntPtr _ ProcessIntPtr = WindowsAPI. Win32API. OpenProcess (_ Type, 1, (uint) m_ProcessID );

IntPtr _ Out = IntPtr. Zero;
For (int z = 0; z! = _ ItemCount; z ++)
{

// Allocate a memory address to save the application name of the process
IntPtr _ StrBufferMemory = WindowsAPI. Win32API. VirtualAllocEx (_ ProcessIntPtr, 0,255, WindowsAPI. Win32API. MEM_COMMIT.MEM_COMMIT, WindowsAPI. Win32API. MEM_PAGE.PAGE_READWRITE );

Byte [] _ OutBytes = new byte [40]; // defines the struct (LVITEM)

Byte [] _ StrIntPtrAddress = BitConverter. GetBytes (_ StrBufferMemory. ToInt32 ());
_ OutBytes [20] = _ StrIntPtrAddress [0];
_ OutBytes [21] = _ StrIntPtrAddress [1];
_ OutBytes [22] = _ StrIntPtrAddress [2];
_ OutBytes [23] = _ StrIntPtrAddress [3];
_ OutBytes [24] = 255;

// Allocate memory to the struct
IntPtr _ Memory = WindowsAPI. Win32API. VirtualAllocEx (_ ProcessIntPtr, 0, _ OutBytes. Length, WindowsAPI. Win32API. MEM_COMMIT.MEM_COMMIT, WindowsAPI. Win32API. MEM_PAGE.PAGE_READWRITE );
// Pass the data to the struct (LVITEM)
WindowsAPI. Win32API. WriteProcessMemory (_ ProcessIntPtr, _ Memory, _ OutBytes, (uint) _ OutBytes. Length, out _ Out );

// Send a message to obtain struct data
WindowsAPI. Win32API. SendMessage (p_ListViewIntPtr, 0x102D, z, _ Memory );

// Obtain struct data
WindowsAPI. Win32API. ReadProcessMemory (_ ProcessIntPtr, _ Memory, _ OutBytes, (uint) _ OutBytes. Length, out _ Out );

// Obtain the pszText address of the struct.
IntPtr _ ValueIntPtr = new IntPtr (BitConverter. ToInt32 (_ OutBytes, 20 ));

Byte [] _ TextBytes = new byte [255]; // obtain pszText data
WindowsAPI. Win32API. ReadProcessMemory (_ ProcessIntPtr, _ ValueIntPtr, _ TextBytes, 255, out _ Out );
// Obtain the process name
String _ ProcessText = System. Text. Encoding. Default. GetString (_ TextBytes). Trim (new Char [] {'/0 '});
// Release the memory
WindowsAPI. Win32API. VirtualFreeEx (_ ProcessIntPtr, _ StrBufferMemory, 0, WindowsAPI. Win32API. MEM_COMMIT.MEM_RELEASE );
WindowsAPI. Win32API. VirtualFreeEx (_ ProcessIntPtr, _ Memory, 0, WindowsAPI. Win32API. MEM_COMMIT.MEM_RELEASE );

If (_ ProcessText = m_ProcessName)
{
WindowsAPI. Win32API. SendMessage (p_ListViewIntPtr, 0x1008, z, 0 );
}
}
}

/// <Summary>
/// Hide a line in the WINDOWS Task Manager that needs to be called all the time and will be refreshed by the task manager
/// </Summary>
/// <Param name = "p_Name"> name, for example, qq.exe </param>
Public void HideTaskmgrListOfName (string p_Name)
{
System. Diagnostics. Process [] _ ProcessList = System. Diagnostics. Process. GetProcessesByName ("taskmgr ");
For (int I = 0; I! = _ ProcessList. Length; I ++)
{
If (_ ProcessList [I]. MainWindowTitle = "Windows Task Manager ")
{
M_ProcessID = _ ProcessList [I]. Id;
WindowsAPI. Win32API. EnumWindowsProc _ EunmControl = new WindowsAPI. Win32API. EnumWindowsProc (NetEnumControl );

WindowsAPI. Win32API. EnumChildWindows (_ ProcessList [I]. main1_whandle, _ EunmControl, 0 );
}
}
}
}


Public class Win32API
{

Public enum MEM_PAGE
{
PAGE_NOACCESS = 0x1,
PAGE_READONLY = 0x2,
PAGE_READWRITE = 0x4,
PAGE_WRITECOPY = 0x8,
PAGE_EXECUTE = 0x10,
PAGE_EXECUTE_READ = 0x20,
PAGE_EXECUTE_READWRITE = 0x40,
PAGE_EXECUTE_READWRITECOPY = 0x50,
PAGE_EXECUTE_WRITECOPY = 0x80,
PAGE_GUARD = 0x100,
Page_nocached = 0x200,
PAGE_WRITECOMBINE = 0x400,
}



Public enum MEM_COMMIT
{
MEM_COMMIT = 0x1000,
MEM_RESERVE = 0x2000,
MEM_DECOMMIT = 0x4000,
MEM_RELEASE = 0x8000,
Apsaradb for MEM_FREE = 0x10000,
MEM_PRIVATE = 0x20000,
MEM_MAPPED = 0x40000,
MEM_RESET = 0x80000,
MEM_TOP_DOWN = 0x100000,
MEM_WRITE_WATCH = 0x200000,
MEM_PHYSICAL = 0x400000,
MEM_IMAGE = 0x1000000
}

[Flags]
Public enum ProcessAccessType
{
PROCESS_TERMINATE = (0x0001 ),
PROCESS_CREATE_THREAD = (0x0002 ),
PROCESS_SET_SESSIONID = (0x0004 ),
PROCESS_VM_OPERATION = (0x0008 ),
PROCESS_VM_READ = (0x0010 ),
PROCESS_VM_WRITE = (0x0020 ),
PROCESS_DUP_HANDLE = (0x0040 ),
PROCESS_CREATE_PROCESS = (0x0080 ),
PROCESS_SET_QUOTA = (0x0100 ),
PROCESS_SET_INFORMATION = (0x0200 ),
PROCESS_QUERY_INFORMATION = (0x0400)
}

[StructLayout (LayoutKind. Sequential, CharSet = CharSet. Auto)]
Public struct STRINGBUFFER
{
[Financialas (UnmanagedType. ByValTStr, SizeConst = 512)]
Public string szText;
}
Public delegate bool EnumWindowsProc (IntPtr p_Handle, int p_Param );


[DllImport ("kernel32.dll")]
Public static extern IntPtr OpenProcess (ProcessAccessType dwDesiredAccess, int bInheritHandle, uint dwProcessId );

[DllImport ("kernel32.dll")]
Public static extern Int32 CloseHandle (IntPtr hObject );

[DllImport ("kernel32.dll")]
Public static extern Int32 ReadProcessMemory (IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte [] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead );

[DllImport ("kernel32.dll")]
Public static extern Int32 WriteProcessMemory (IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte [] buffer, UInt32 size, out IntPtr lpNumberOfBytesWritten );

[DllImport ("kernel32.dll")]
Public static extern IntPtr VirtualAllocEx (IntPtr hProcess, int lpAddress, int dwSize, MEM_COMMIT flAllocationType, MEM_PAGE flProtect );

[DllImport ("kernel32.dll")]
Public static extern IntPtr VirtualFreeEx (IntPtr hProcess, IntPtr lpAddress, int dwSize, MEM_COMMIT dwFreeType );

[DllImport ("User32.dll", CharSet = CharSet. Auto)]
Public static extern int GetWindowText (IntPtr hWnd, out STRINGBUFFER text, int nMaxCount );

[DllImport ("User32.dll", CharSet = CharSet. Auto)]
Public static extern int GetClassName (IntPtr hWnd, out STRINGBUFFER ClassName, int nMaxCount );

[DllImport ("user32.dll", CharSet = CharSet. Auto)]
Public static extern int SendMessage (IntPtr hWnd, int Msg, int wParam, int lParam );

[DllImport ("user32.dll", CharSet = CharSet. Auto)]
Public static extern int SendMessage (IntPtr hWnd, int Msg, int wParam, IntPtr lParam );

[DllImport ("user32.dll")]
Public static extern int EnumChildWindows (IntPtr hWndParent, EnumWindowsProc ewp, int lParam );

}



}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.