MFC任务管理器task manager----进程的挂起与恢复--NtSuspendProcess&&NtResumeProcess
http://hi.baidu.com/xbbsh/blog/item/b73d3125462201084c088db1.html
--------------------------------------------------
.h
pubilc:
typedef DWORD (WINAPI *NtSuspendProcess)(HANDLE ProcessHandle);
typedef DWORD (WINAPI *NtResumeProcess)(HANDLE hProcess);
NtSuspendProcess m_NtSuspendProcess;
NtResumeProcess m_NtResumeProcess;
.cpp:
void CPage2::OnBnClickedResume()
{
// TODO: 在此添加控件通知处理程序代码
int nIdx=m_list2.GetNextItem(-1,LVNI_SELECTED);
CString process=m_list2.GetItemText(nIdx,1);
DWORD processID= _ttol(process.GetBuffer(0));
HANDLE hProcess = OpenProcess( PROCESS_SUSPEND_RESUME ,//暂停时用这个(P.._S.._R..)标志
FALSE, (DWORD)processID );
if (hProcess)
{
HMODULE h_module=LoadLibrary(L"ntdll.dll");
m_NtResumeProcess=(NtResumeProcess)GetProcAddress(h_module,"NtResumeProcess");
m_NtResumeProcess(hProcess);
}
}
太晚了 睡觉睡觉。。。。。。。
--------------------------------------------------
.h
#pragma once
#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
#include <string>
#include <tchar.h>
//#include <ntifs.h>
#include <Psapi.h>
#pragma comment (lib,"Psapi.lib")
void ErrorExit(LPTSTR lpszFunction);
//--------------------------------------------------
// for cpu 暂停
//方法1 不可关闭本程序,否则进程会退出
long DbgUiConnectToDbg_ntdll();
//long (*DbgUiConnectToDbg)();//这样会报重复定义
long DbgUiDebugActiveProcess_ntdll(HANDLE ProcessHandle);//暂停
long DbgUiStopDebugging_ntdll(HANDLE ProcessHandle);//恢复
//方法2 可关闭本程序
DWORD NtSuspendProcess_ntdll(HANDLE hProcess);//暂停
DWORD NtResumeProcess_ntdll(HANDLE hProcess);//恢复
//要先调用这个
void LoadNtDllFun();
//--------------------------------------------------
class win_proc_public
{
public:
win_proc_public(void);
~win_proc_public(void);
public:
std::string GetExeFullName(HANDLE hProcess)
{
std::string r = "";
//HANDLE hProcess = 0;
char lpImageFileName[2049] = {0};
DWORD nSize = 2048;
//hProcess = getm
DWORD len = GetProcessImageFileName(hProcess, lpImageFileName, nSize);
if (len < 1)
{
//不能直接退出,因为有些权限是得不到的
//ErrorExit("GetExeFullName: ");
}
//len = GetModuleFileNameEx(hProcess, lpImageFileName, nSize);
r = lpImageFileName;
r = DosDevicePath2LogicalPath(r.c_str());
return r;
}//
//将 "\Device\HarddiskVolume2" 等转换为 "D:\"
//DosDevicePath2LogicalPath代码摘自:ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.WIN32COM.v10.en/fileio/fs/obtaining_a_file_name_from_a_file_handle.htm
std::string DosDevicePath2LogicalPath(LPCTSTR lpszDosPath)
{
std::string strResult = "";
// Translate path with device name to drive letters.
TCHAR szTemp[MAX_PATH];
szTemp[0] = '\0';
if ( lpszDosPath==NULL || !GetLogicalDriveStrings(_countof(szTemp)-1, szTemp) )
{
return strResult;
}
TCHAR szName[MAX_PATH];
TCHAR szDrive[3] = TEXT(" :");
BOOL bFound = FALSE;
TCHAR* p = szTemp;
do{
// Copy the drive letter to the template string
*szDrive = *p;
// Look up each device name
if ( QueryDosDevice(szDrive, szName, _countof(szName)) )
{
UINT uNameLen = (UINT)_tcslen(szName);
if (uNameLen < MAX_PATH)
{
bFound = _tcsnicmp(lpszDosPath, szName, uNameLen) == 0;
if ( bFound )
{
// Reconstruct pszFilename using szTemp
// Replace device path with DOS path
TCHAR szTempFile[MAX_PATH];
_stprintf(szTempFile, TEXT("%s%s"), szDrive, lpszDosPath+uNameLen);
strResult = szTempFile;
}
}
}
// Go to the next NULL character.
while (*p++);
} while (!bFound && *p); // end of string
return strResult;
}//
void mainaaa()
{
GetProcessList( );
}
BOOL GetProcessList( )
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
return( FALSE );
}
pe32.dwSize = sizeof( PROCESSENTRY32 );
if( !Process32First( hProcessSnap, &pe32 ) )
{
CloseHandle( hProcessSnap );
return( FALSE );
}
do
{
printf( "\n\n"
"=====================================================" );
printf( "\nPROCESS NAME: %5s", pe32.szExeFile);
printf( "\n"
"-----------------------------------------------------" );
dwPriorityClass = 0;
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
//hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pe32.th32ProcessID );
if( hProcess == NULL )
{
printf("erro");
}
else
{
dwPriorityClass = GetPriorityClass( hProcess );
if( !dwPriorityClass )
printf("erro");
//--------------------------------------------------
//clq add 程序全路径
//char szFilePath[256] = {0};
////HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,pe32.th32ProcessID);
//if ( GetProcessImageFileName(hProcess,szFilePath,MAX_PATH)!=0 )
//{
// //mystring strFilePath = CCommon::DosDevicePath2LogicalPath(szFilePath);
//}
std::string exename = GetExeFullName(hProcess);
printf( "\n path = %s", exename.c_str() );
//--------------------------------------------------
// CloseHandle( hProcess );
}
printf( "\n process ID = %d", pe32.th32ProcessID );
printf( "\n thread count = %d", pe32.cntThreads );
printf( "\n parent process ID = %d", pe32.th32ParentProcessID );
printf( "\n Priority Base = %d", pe32.pcPriClassBase );
if( dwPriorityClass )
printf( "\n Priority Class = %d", dwPriorityClass );
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
return( TRUE );
}//
public:
static void test1()
{
win_proc_public proc;
proc.mainaaa();
test2(4008);
}//
static void test2(DWORD pid)
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
//if (!GetProcessTimes(hProcess, &creation_time, &exit_time, &kernel_time, &user_time))
//{
// return -1;
//}
if (hProcess == NULL) return;
LoadNtDllFun();
//DbgUiConnectToDbg_ntdll();
//long r = DbgUiDebugActiveProcess_ntdll(hProcess);//暂停//调用后不能停止程序否则被停止的程序会被强制退出(相当于调试器停止?)
//::Sleep(5*60*1000);
//r = DbgUiStopDebugging_ntdll(hProcess);//恢复运行
NtSuspendProcess_ntdll(hProcess);//暂停
NtResumeProcess_ntdll(hProcess);//恢复
}//
};
--------------------------------------------------
.cpp
#include "win_proc_public.h"
win_proc_public::win_proc_public(void)
{
}
win_proc_public::~win_proc_public(void)
{
}
//--------------------------------------------------
// for cpu 暂停
//方法1
long (__stdcall *DbgUiConnectToDbg_p)();//在 .h 这样会报重复定义
long (__stdcall *DbgUiDebugActiveProcess_p)(HANDLE ProcessHandle);//暂停
long (__stdcall *DbgUiStopDebugging_p)(HANDLE ProcessHandle);//恢复
//方法2
//NtResumeProcess
DWORD (WINAPI *NtResumeProcess_p)(HANDLE hProcess);//暂停
DWORD (WINAPI *NtSuspendProcess_p)(HANDLE hProcess);//恢复
void LoadNtDllFun()
{
HMODULE dllhandle;
//dwret:dword;
//ProcessHandle: dword;
//begin
dllhandle = LoadLibrary("ntdll.dll");
if (dllhandle != 0 )
{
DbgUiConnectToDbg_p = (long (__stdcall *)()) GetProcAddress(dllhandle, "DbgUiConnectToDbg");
DbgUiDebugActiveProcess_p = (long (__stdcall *)(HANDLE))GetProcAddress(dllhandle, "DbgUiDebugActiveProcess");
DbgUiStopDebugging_p = (long (__stdcall *)(HANDLE))GetProcAddress(dllhandle, "DbgUiStopDebugging");
//MyDbgUiConnectToDbg;
//ProcessHandle:=OpenProcess(process_all_access, False, findprocess("winlogon.exe"));
////messagebox(0,pchar(inttohex(ProcessHandle,8)),"aa",0);
//dwret:=MyDbgUiDebugActiveProcess(ProcessHandle);
//if dwret<>0 then messagebox(0,pchar("保护失败"),"提示",0) else
//messagebox(0,pchar("保护成功,来结束我吧!"),"提示",0)
NtResumeProcess_p = (DWORD (__stdcall *)(HANDLE))GetProcAddress(dllhandle, "NtResumeProcess");
NtSuspendProcess_p = (DWORD (__stdcall *)(HANDLE))GetProcAddress(dllhandle, "NtSuspendProcess");
}
//CloseHandle(dllhandle);
}//
long DbgUiConnectToDbg_ntdll()
{
return DbgUiConnectToDbg_p();
}//
long DbgUiDebugActiveProcess_ntdll(HANDLE ProcessHandle)
{
return DbgUiDebugActiveProcess_p(ProcessHandle);
}//
long DbgUiStopDebugging_ntdll(HANDLE ProcessHandle)
{
return DbgUiStopDebugging_p(ProcessHandle);
}//
DWORD NtResumeProcess_ntdll(HANDLE hProcess)//暂停
{
return NtResumeProcess_p(hProcess);
}
DWORD NtSuspendProcess_ntdll(HANDLE hProcess)//恢复
{
return NtSuspendProcess_p(hProcess);
}
/*
这个据说也成
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID );
if (hProcess)
{
HINSTANCE h_module = LoadLibrary(“ntdll.dll”);
NtProcess mProcess = (NtProcess)GetProcAddress(h_module, “NtResumeProcess”); //NtResumeProcess NtSuspendProcess
mProcess(hProcess);
}
其中processID为进程PID号码
休眠还是恢复,随你选择
*/
http://www.cnblogs.com/-clq/archive/2012/03/15/2397533.html
MFC任务管理器task manager----进程的挂起与恢复--NtSuspendProcess&&NtResumeProcess的更多相关文章
- linux进程的挂起和恢复
进程的挂起及恢复 #ctrl+z:挂起,程序放到后台,程序没有结束. #jobs:查看被挂起的程序工作号 恢复进程执行时,有两种选择:fg命令将挂起的作业放回到前台执行:用bg命令将挂起的作业放到后台 ...
- C# 进程的挂起与恢复
1. 源起: 仍然是模块化编程所引发的需求.产品经理难伺候,女产品经理更甚之~:p 纯属戏谑,技术方案与产品经理无关,芋头莫怪! VCU10项目重构,要求各功能模块以独立进程方式实现,比如:音视频转换 ...
- Linux中线程的挂起与恢复(进程暂停)
http://www.linuxidc.com/Linux/2013-09/90156.htm 今天在网上查了一下Linux中对进程的挂起与恢复的实现,相关资料少的可怜,大部分都是粘贴复制.也没有完整 ...
- 【C#】调度程序进程已挂起,但消息仍在处理中;
环境:WPF.弹窗,messageBox.show();错误信息:调度程序进程已挂起,但消息仍在处理中:解决方法:Dispatcher.BeginInvoke(new Action(()=>{ ...
- 【Hook技术】实现从"任务管理器"中保护进程不被关闭 + 附带源码 + 进程保护知识扩展
[Hook技术]实现从"任务管理器"中保护进程不被关闭 + 附带源码 + 进程保护知识扩展 公司有个监控程序涉及到进程的保护问题,需要避免用户通过任务管理器结束掉监控进程,这里使用 ...
- Swoole 理解manager进程和worker进程的启动顺序,以及演示如何停止或者重启服务端。
测试的代码主要功能:开启一个tcp服务器.然后设置了管理进程和工作进程start的回调进行更名.设置了pid_file保存了服务端启动的mast进程. <?php //创建Server对象,监听 ...
- Day035--Python--管道, Manager, 进程池, 线程切换
管道 #创建管道的类: Pipe([duplex]):在进程之间创建一条管道,并返回元组(conn1,conn2),其中conn1,conn2表示管道两端的连接对象,强调一点:必须在产生Process ...
- My To Do List (Task Manager)
My To Do List (Task Manager) With everything that business owners deal with throughout their day, th ...
- Windows的任务管理器怎么显示进程的图标
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:Windows的任务管理器怎么显示进程的图标.
随机推荐
- hibernate批量删除和更新数据
转载自:http://blog.csdn.net/yuhua3272004/article/details/2909538 Hibernate3.0 採用新的基于ANTLR的HQL/SQL查询翻译器, ...
- hdu 2222 Keywords Search ac自己主动机
点击打开链接题目链接 Keywords Search Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
- WCF - 地址
WCF顾名思义 即解决在windows平台下与各种平台中的程序之间通信的问题 而终结点则是WCF通信的唯一手段 终结点承载了所有通信的功能 一个WCF服务是通过对应的终结点发布出来的 发布出来的数据称 ...
- MyEclipse_6.0.1GA_E3.3.1集成版下载地址
因在开发中经常使用到myeclipse 对比相关版本,还是觉得6.0 –6.5 比较适合开发,其他的开发起来比较卡,下面是下载地址 MyEclipse_6.0.1GA_E3.3.1集成版下载地址: ...
- 关于String的hashCode
String str=new String("abc"); String str2="abc"; System.out.println(str.hashCode ...
- 禁止鼠标多次点击选中div中的文字
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Fire ...
- jsp中Java代码中怎么获取jsp页面元素
举例,页面元素<td><input value="${sl }" type="text" id="sl" name=& ...
- Android开发中用友盟做分享的一些坑
仅限于用5.1.4版本的 按照友盟分享的API在自己的代码中修改: 1.微信分享需要打包APK文件,数字签名与微信开发申请的要一致 2.此name中属性不能修改 value为友盟的申请的appkey ...
- linux常用命令之tail
从指定点开始将文件写到标准输出.使用tail命令的-f选项可以方便的查阅正在改变的日志文件,tail -f filename会把filename里最尾部的内容显示在屏幕上,并且不但刷新,使你看到最新的 ...
- Visual Studio2010 安装msdn
1.注册VS2010 断网(不要冒险)->运行Microsoft Visual Studio 2010->帮助->注册产品->YCFHQ-9DWCY-DKV88-T2TMH-G ...