判定元件 typedef LONG(NTAPI*NtSuspendProcess)(在句柄进程句柄中); typedef LONG(NTAPI*NtResumeProcess)(在句柄进程句柄中); NtSuspendProcess dSuspendPro
判定元件 typedef LONG(NTAPI*NtSuspendProcess)(在句柄进程句柄中); typedef LONG(NTAPI*NtResumeProcess)(在句柄进程句柄中); NtSuspendProcess dSuspendProcess=nullptr; NtResumeProcess-dResumeProcess=nullptr; int获取_pid(){ DWORD procs[4096],字节; int out=-1; if(!enumprocess(procs,sizeof(procs),&bytes)){ 返回-1; } 对于(大小i=0;i判定元件 typedef LONG(NTAPI*NtSuspendProcess)(在句柄进程句柄中); typedef LONG(NTAPI*NtResumeProcess)(在句柄进程句柄中); NtSuspendProcess dSuspendPro,c,windows,multithreading,winapi,multiprocessing,C,Windows,Multithreading,Winapi,Multiprocessing,判定元件 typedef LONG(NTAPI*NtSuspendProcess)(在句柄进程句柄中); typedef LONG(NTAPI*NtResumeProcess)(在句柄进程句柄中); NtSuspendProcess dSuspendProcess=nullptr; NtResumeProcess-dResumeProcess=nullptr; int获取_pid(){ DWORD procs[4096],字节; int out=-1; if(!enumprocess(procs
/*Find, suspend, resume Win32 C++
*Written by jimmio92. No rights reserved. Public domain.
*NO WARRANTY! NO LIABILITY! (obviously)
*/
#include <windows.h>
#include <psapi.h>
typedef LONG (NTAPI *NtSuspendProcess)(IN HANDLE ProcessHandle);
typedef LONG (NTAPI *NtResumeProcess)(IN HANDLE ProcessHandle);
NtSuspendProcess dSuspendProcess = nullptr;
NtResumeProcess dResumeProcess = nullptr;
int get_the_pid() {
DWORD procs[4096], bytes;
int out = -1;
if(!EnumProcesses(procs, sizeof(procs), &bytes)) {
return -1;
}
for(size_t i = 0; i < bytes/sizeof(DWORD); ++i) {
TCHAR name[MAX_PATH] = "";
HMODULE mod;
HANDLE p = nullptr;
bool found = false;
p = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, procs[i]);
if(p == nullptr)
continue;
DWORD unused_bytes_for_all_modules = 0;
if(EnumProcessModules(p, &mod, sizeof(mod), &unused_bytes_for_all_modules)) {
GetModuleBaseName(p, mod, name, sizeof(name));
//change this to use an array of names or whatever fits your need better
if(strcmp(name, "Steam.exe") == 0 || strcmp(name, "chrome.exe") == 0) {
out = procs[i];
found = true;
}
}
CloseHandle(p);
if(found) break;
}
return out;
}
void suspend_process_by_id(int pid) {
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(h == nullptr)
return;
dSuspendProcess(h);
CloseHandle(h);
}
void resume_process_by_id(int pid) {
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if(h == nullptr)
return;
dResumeProcess(h);
CloseHandle(h);
}
void init() {
//load NtSuspendProcess from ntdll.dll
HMODULE ntmod = GetModuleHandle("ntdll");
dSuspendProcess = (NtSuspendProcess)GetProcAddress(ntmod, "NtSuspendProcess");
dResumeProcess = (NtResumeProcess)GetProcAddress(ntmod, "NtResumeProcess");
}
int main() {
init();
int pid = get_the_pid();
if(pid < 0) {
printf("Steam.exe and chrome.exe not found");
}
suspend_process_by_id(pid);
//wait ten seconds for demonstration purposes
Sleep(10000);
resume_process_by_id(pid);
return 0;
}