• win10打印所有进程


    #include <map>
    #include <iostream>
    #include <string>
    
    #include <windows.h>
    #include <TlHelp32.h> // Never include win32 heads before window.h
    
    
    bool printAllProcess(std::map<std::wstring, int> &_mapProcess, bool is_print = true)
    {
    	PROCESSENTRY32 pe32;
    	pe32.dwSize = sizeof(pe32);
    
    	HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    	if (hProcessSnap == INVALID_HANDLE_VALUE) {
    		std::cout << "CreateToolhelp32Snapshot Error!" << std::endl;;
    		return false;
    	}
    
    	BOOL bResult = Process32First(hProcessSnap, &pe32);
    
    	int num(0);
    
    	while (bResult)
    	{
    		std::wstring name = pe32.szExeFile;
    		int id = pe32.th32ProcessID;
    		if (is_print)
    		{
    			std::cout << "[" << ++num << "]: " << "--ProcessID:" << id;
    			std::wcout << "--Process Name:" << name << std::endl;
    		}
    		_mapProcess.insert(std::pair<std::wstring, int>(name, id)); 
    		bResult = Process32Next(hProcessSnap, &pe32);
    	}
    
    	CloseHandle(hProcessSnap);
    	return true;
    }
    

      

  • 相关阅读:
    Springboot中使用Scala开发
    aliyun阿里云Maven仓库地址
    css文字滚动
    随笔
    下拉菜单事件
    微信分享
    微信分享功能
    随笔记
    全屏设置
    判定复选框的选中状态
  • 原文地址:https://www.cnblogs.com/alexYuin/p/9697636.html
Copyright © 2020-2023  润新知