所以我想获取系统(Windows)上正在运行的所有进程的列表,并以以下格式打印出进程ID,其名称为:
Process ID - Process Name
代码可以正常工作,并且打印出进程ID和进程名称,但是即使名称旁边的进程ID发生了变化,该进程名称也始终保持不变(例如,示例输出):
Process ID - Process Name
13044 007FF61C
13220 007FF61C
11752 007FF61C
我获取程序并打印ID和名称的代码如下:
void misc::get_processes(void) {
HANDLE process_snapshot;
PROCESSENTRY32 pe32;
process_snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (process_snapshot == INVALID_HANDLE_VALUE)
cout << "CreateToolhelp32Snapshot() returned INVALID_HANDLE_VALUE" << endl;
pe32.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(process_snapshot, &pe32))
cout << "Process32First() returned an error" << endl;
cout << "Process ID - Process Name" << endl;
do
cout << pe32.th32ProcessID << "\t\t" << pe32.szExeFile << endl;
while (Process32Next(process_snapshot, &pe32));
}
我还想包括重新启动程序时进程名称更改的信息,例如:
006FF74C
收件人:
0019FA6C