windows列出所有进程示例

来源:互联网 发布:双色球破解软件 编辑:程序博客网 时间:2024/05/21 09:27
//列出当前所有进程示例
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tlhelp32.h>
void PrintProcessList();
int main(){
PrintProcessList();
system("pause");
return 0;
}
void PrintProcessList(){
HANDLE pHandle;
PROCESSENTRY32 proc;
DWORD procId;
pHandle = CreateToolhelp32Snapshot(0x2, 0x0);
if (pHandle == INVALID_HANDLE_VALUE){
return;
}
proc.dwSize = sizeof(PROCESSENTRY32);
while (Process32Next(pHandle, &proc)){
printf("ProcessName : %s - ProcessID : %d\r\n", proc.szExeFile, proc.th32ProcessID);
}
CloseHandle(pHandle);
return;
}