本文共 1708 字,大约阅读时间需要 5 分钟。
#include #include #include #include #include using namespace std;// 进程信息map mapPrsInfo;BOOL KillProcess(DWORD dwProcessId) { HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessId); BOOL bKill= TerminateProcess(hProcess,0); if(!bKill) { return FALSE; } return TRUE;}bool EnumProcess() { //CreateToolhelp32Snapshot //Process32Next //Process32First PROCESSENTRY32 pe32; pe32.dwSize=sizeof(PROCESSENTRY32); HANDLE hSnapshot= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if(INVALID_HANDLE_VALUE==hSnapshot) { return false; } if(Process32First(hSnapshot,&pe32)) { do { mapPrsInfo[pe32.th32ProcessID] = string(pe32.szExeFile); printf("ID:%d,Name:%s\n",pe32.th32ProcessID,pe32.szExeFile); } while (Process32Next(hSnapshot,&pe32)); } return false; } bool EnablePri() { //OpenProcessToken //LookupPrivilegeValue //AdjustTokenPrivileges() HANDLE TokenHandle; TOKEN_PRIVILEGES tkp; tkp.PrivilegeCount=1; BOOL bOpen= OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&TokenHandle); if(!bOpen) { return false; } BOOL bLook= LookupPrivilegeValue(NULL,SE_SECURITY_NAME,&tkp.Privileges[0].Luid); if(!bLook) { return false; } BOOL bAdjust= AdjustTokenPrivileges(TokenHandle,false,&tkp,sizeof(tkp),NULL,NULL); return(GetLastError()==ERROR_SUCCESS); } int _tmain(int argc, _TCHAR* argv[]){ if(!EnablePri()) { printf("EnablePri fail\n"); return 0; } if(EnumProcess()) { printf("EnumProcess fail\n"); getchar(); return 0; } printf("InPut Process PID:"); DWORD dwProcessId; scanf("%d",&dwProcessId); system("pause"); return 0;}
转自:
其他:
转载于:https://www.cnblogs.com/jdfemqi/p/3445212.html