VC prohibits the end of this process in Task Manager

Source: Internet
Author: User

Switch from Baidu Space: HTTP://HI.BAIDU.COM/175943462/ITEM/657905E13B73B70B8D3EA8BB

A mention of process protection, especially under Windows, is not the safest, only more secure. The following code is at the user level, intercepting the message when the Task manager's this process name (Test.exe) is selected, to prevent the task manager from ending the process (of course you can end it with other process tools!). )。 Mainly to learn the methods, familiar with several structures, several APIs:

1, Lvitem

Specifies or receives the attributes of a List-view item. This structure have been updated to support a new mask value (lvif_indent) that enables item indenting. This structure supersedes the LV_ITEM structure.

(My level of English can make up to see it, I believe you are no problem!) )

View Plaincopy to Clipboardprint?
typedef struct _LVITEM {
UINT Mask;
int IItem;
int ISubItem;
UINT State;
UINT Statemask;
LPTSTR PszText;
int Cchtextmax;
int iImage;
LPARAM LPARAM;
#if (_win32_ie >= 0x0300)
int iindent;
#endif
#if (_win32_ie >= 0x560)
int igroupid;
UINT CColumns; Tile view Columns
Puint Pucolumns;
#endif
} Lvitem, *lplvitem;
typedef struct _LVITEM {
UINT Mask;
int IItem;
int ISubItem;
UINT State;
UINT Statemask;
LPTSTR PszText;
int Cchtextmax;
int iImage;
LPARAM LPARAM;
#if (_win32_ie >= 0x0300)
int iindent;
#endif
#if (_win32_ie >= 0x560)
int igroupid;
UINT CColumns; Tile view Columns
Puint Pucolumns;
#endif
} Lvitem, *lplvitem;

2, FindWindow and FindWindowEx

View Plaincopy to Clipboardprint?
Find Task Manager ListView window Handle
HWND hwnd;
Hwnd=findwindow ("#32770", _t ("Windows Task Manager");
Hwnd=findwindowex (hwnd,0, "#32770", 0);
Hwnd=findwindowex (hwnd,0, "SysListView32", 0);

Windows Task Manager has not been started to return
if (!hwnd)
Return
Find Task Manager ListView window Handle
HWND hwnd;
Hwnd=findwindow ("#32770", _t ("Windows Task Manager");
Hwnd=findwindowex (hwnd,0, "#32770", 0);
Hwnd=findwindowex (hwnd,0, "SysListView32", 0);

Windows Task Manager has not been started to return
if (!hwnd)
Return

3, the above structure and API familiarity, then look at this function!

View Plaincopy to Clipboardprint?
/************************************************************************/
/* Function Description: Disable the end of this process in Task Manager
/* Parameter: None
/* return value: void
/* By:koma 2009.07.27 23:50
/************************************************************************/
void Fuckwindowsmanager ()
{
HWND hwnd;
int iitem=0;
Lvitem Lvitem, *plvitem;
Char Itembuf[512],*pitem;
DWORD PID;
HANDLE hprocess;

Find Task Manager ListView window Handle
Hwnd=findwindow ("#32770", _t ("Windows Task Manager");
Hwnd=findwindowex (hwnd,0, "#32770", 0);
Hwnd=findwindowex (hwnd,0, "SysListView32", 0);

Windows Task Manager has not been started to return
if (!hwnd)
Return
Else
{
The target process is not specified to return
Iitem=sendmessage (hwnd,lvm_getnextitem,-1,lvni_selected);
if (iitem==-1)
Return
Else
{
GetWindowThreadProcessId (hwnd, &PID);

The get process handle operation failed to return
Hprocess=openprocess (PROCESS_ALL_ACCESS,FALSE,PID);
if (!hprocess)
Return
Else
{
Plvitem= (lvitem*) VirtualAllocEx (hprocess, NULL, sizeof (Lvitem), Mem_commit, page_readwrite);
Pitem= (char*) VirtualAllocEx (hprocess, NULL, MB, mem_commit, page_readwrite);

Unable to allocate memory is returned
if ((!plvitem) | | | (!pitem))
Return
Else
{
lvitem.cchtextmax=512;
Lvitem.isubitem=1;//pid
lvitem.isubitem=0; ProcessName
Lvitem.psztext=pitem;
WriteProcessMemory (hprocess, Plvitem, &lvitem, sizeof (Lvitem), NULL);
SendMessage (hwnd, Lvm_getitemtext, (WPARAM) IItem, (LPARAM) plvitem);
ReadProcessMemory (hprocess, Pitem, Itembuf, MB, NULL);

Compare strings and change Test.exe to your process image name
CString str = (CString) itembuf;
if (Str.comparenocase (_t ("Test.exe") = = = 0)
{
HWND Hwnd=findwindow (null,_t ("Windows Task Manager"));
SendMessage (hwnd,wm_destroy,0,0);
Sleep (10);
MessageBox (null,_t ("Disable shutting down the system critical process!") "), _t (" hint "), Mb_iconerror | MB_OK);
}
}
}
}
}

Freeing memory
CloseHandle (HWND);
CloseHandle (hprocess);
VirtualFreeEx (hprocess, Plvitem, 0, mem_release);
VirtualFreeEx (hprocess, Pitem, 0, mem_release);
}
/************************************************************************/
/* Function Description: Disable the end of this process in Task Manager
/* Parameter: None
/* return value: void
/* By:koma 2009.07.27 23:50
/************************************************************************/
void Fuckwindowsmanager ()
{
HWND hwnd;
int iitem=0;
Lvitem Lvitem, *plvitem;
Char Itembuf[512],*pitem;
DWORD PID;
HANDLE hprocess;

Find Task Manager ListView window Handle
Hwnd=findwindow ("#32770", _t ("Windows Task Manager");
Hwnd=findwindowex (hwnd,0, "#32770", 0);
Hwnd=findwindowex (hwnd,0, "SysListView32", 0);

Windows Task Manager has not been started to return
if (!hwnd)
Return
Else
{
The target process is not specified to return
Iitem=sendmessage (hwnd,lvm_getnextitem,-1,lvni_selected);
if (iitem==-1)
Return
Else
{
GetWindowThreadProcessId (hwnd, &PID);

The get process handle operation failed to return
Hprocess=openprocess (PROCESS_ALL_ACCESS,FALSE,PID);
if (!hprocess)
Return
Else
{
Plvitem= (lvitem*) VirtualAllocEx (hprocess, NULL, sizeof (Lvitem), Mem_commit, page_readwrite);
Pitem= (char*) VirtualAllocEx (hprocess, NULL, MB, mem_commit, page_readwrite);

Unable to allocate memory is returned
if ((!plvitem) | | | (!pitem))
Return
Else
{
lvitem.cchtextmax=512;
Lvitem.isubitem=1;//pid
lvitem.isubitem=0; ProcessName
Lvitem.psztext=pitem;
WriteProcessMemory (hprocess, Plvitem, &lvitem, sizeof (Lvitem), NULL);
SendMessage (hwnd, Lvm_getitemtext, (WPARAM) IItem, (LPARAM) plvitem);
ReadProcessMemory (hprocess, Pitem, Itembuf, MB, NULL);

Compare strings and change Test.exe to your process image name
CString str = (CString) itembuf;
if (Str.comparenocase (_t ("Test.exe") = = = 0)
{
HWND Hwnd=findwindow (null,_t ("Windows Task Manager"));
SendMessage (hwnd,wm_destroy,0,0);
Sleep (10);
MessageBox (null,_t ("Disable shutting down the system critical process!") "), _t (" hint "), Mb_iconerror | MB_OK);
}
}
}
}
}

Freeing memory
CloseHandle (HWND);
CloseHandle (hprocess);
VirtualFreeEx (hprocess, Plvitem, 0, mem_release);
VirtualFreeEx (hprocess, Pitem, 0, mem_release);
}

4. VC Source Code Project

1:http://www.rayfile.com/files/31bedea3-7b13-11de-9d03-0014221b798a/

2:http://download.csdn.net/source/1524075

http://blog.csdn.net/dingxz105090/article/details/27367937

VC prohibits the end of this process in Task Manager

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.