VC++实现进程冻结与解冻
2021/4/26 7:29:07
本文主要是介绍VC++实现进程冻结与解冻,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
VC++实现进程冻结与解冻
冻结进程
#include
int main(int argc,char *argv[])
{
PROCESSENTRY32 pe32;
pe32.dwSize=sizeof(pe32);
unsigned long Pid;
HANDLE hProcessSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap==INVALID_HANDLE_VALUE)
{
printf("CreateToolhelp32Snapshot调用失败!");
return -1;
}
BOOL b=::Process32First(hProcessSnap,&pe32);
while(b)
{
if(!strcmp(pe32.szExeFile,argv[1]))
{
printf("Find %s ok!/n",pe32.szExeFile);
Pid=pe32.th32ProcessID;
break;
}
b=::Process32Next(hProcessSnap,&pe32);
}
::CloseHandle(hProcessSnap);
THREADENTRY32 th32;
th32.dwSize=sizeof(th32);
HANDLE hThreadSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
if(hThreadSnap==INVALID_HANDLE_VALUE)
{
printf("CreateToolhelp32Snapshot调用失败!");
return -1;
}
b=::Thread32First(hThreadSnap,&th32);
while(b)
{
if(th32.th32OwnerProcessID==Pid)
{
HANDLE oth=OpenThread(THREAD_ALL_ACCESS,FALSE,th32.th32ThreadID);
if(!(::SuspendThread(oth)))
{
printf("Onlock Thread id:%d/n",th32.th32ThreadID);
printf("Onlock ThreadOwnerProcessID:%d/n",th32.th32OwnerProcessID);
printf("Onlock ExeFileName %s/n",pe32.szExeFile);
}
CloseHandle(oth);
break;
}
::Thread32Next(hThreadSnap,&th32);
}
::CloseHandle(hThreadSnap);
return 0;
}
解冻进程
#include
int main(int argc,char *argv[])
{
PROCESSENTRY32 pe32;
pe32.dwSize=sizeof(pe32);
unsigned long Pid;
HANDLE hProcessSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(hProcessSnap==INVALID_HANDLE_VALUE)
{
printf("CreateToolhelp32Snapshot调用失败!");
return -1;
}
BOOL b=::Process32First(hProcessSnap,&pe32);
while(b)
{
if(!strcmp(pe32.szExeFile,argv[1]))
{
printf("Find %s ok!/n",pe32.szExeFile);
Pid=pe32.th32ProcessID;
break;
}
b=::Process32Next(hProcessSnap,&pe32);
}
::CloseHandle(hProcessSnap);
THREADENTRY32 th32;
th32.dwSize=sizeof(th32);
HANDLE hThreadSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);
if(hThreadSnap==INVALID_HANDLE_VALUE)
{
printf("CreateToolhelp32Snapshot调用失败!");
return -1;
}
b=::Thread32First(hThreadSnap,&th32);
while(b)
{
if(th32.th32OwnerProcessID==Pid)
{
HANDLE oth=OpenThread(THREAD_ALL_ACCESS,FALSE,th32.th32ThreadID);
if(::ResumeThread(oth))
{
printf("Unlock Thread id:%d/n",th32.th32ThreadID);
printf("Unlock ThreadOwnerProcessID:%d/n",th32.th32OwnerProcessID);
printf("Unlock ExeFileName %s/n",pe32.szExeFile);
}
CloseHandle(oth);
break;
}
::Thread32Next(hThreadSnap,&th32);
}
::CloseHandle(hThreadSnap);
return 0;
}
这篇关于VC++实现进程冻结与解冻的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-27TypeScript面试真题解析与实战指南
- 2024-12-27TypeScript大厂面试真题详解与解析
- 2024-12-26怎么使用nsenter命令进入容器?-icode9专业技术文章分享
- 2024-12-26导入文件提示存在乱码,请确定使用的是UTF-8编码怎么解决?-icode9专业技术文章分享
- 2024-12-26csv文件怎么设置编码?-icode9专业技术文章分享
- 2024-12-25TypeScript基础知识详解
- 2024-12-25安卓NDK 是什么?-icode9专业技术文章分享
- 2024-12-25caddy 可以定义日志到 文件吗?-icode9专业技术文章分享
- 2024-12-25wordfence如何设置密码规则?-icode9专业技术文章分享
- 2024-12-25有哪些方法可以实现 DLL 文件路径的管理?-icode9专业技术文章分享