c++ - When looping through all processes, the process name stays the same but the process ID changes
问题描述
So I want to get the list of all processes running on the system (Windows) and print out the process ID with the name in this format:
Process ID - Process Name
The code works and it prints out the process ID and process name but the process name stays the same all the time even though the process ID beside the name is changing, for instance (example output):
Process ID - Process Name
13044 007FF61C
13220 007FF61C
11752 007FF61C
My code which gets the processes and prints the ID and name looks like this:
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));
}
Also I wanted to include that the process name changes when I restart the program, for instance from:
006FF74C
to:
0019FA6C
解决方案
推荐阅读
- ofbiz - 如何将数据写入表 catalina_session?
- sql-server - 在非聚集索引中添加所有主键约束
- css - 是否可以调整 mat-form-field-outline 厚度?
- blazor - 只能在开发环境中访问的 Blazor 组件库
- python - Boto3 - S3 存储桶策略更新
- sql - 仅捕获相关记录,而与 hive 中的整批无关
- html - 如何更改按钮内文本的悬停颜色
- javascript - Nodejs创建不同的发布请求
- angular - 如何将 formControl 绑定到具有对象 id 的对象?PrimeNG 下拉菜单
- image - 更改图像尺寸 - 大量导入时出错 - Prestashop 1.7