windows api 枚举进程pid
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                windows api 枚举进程pid
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
#include <windows.h> #include <stdio.h> #include <tchar.h> #include <psapi.h>// gcc a.c -lpsapi -o a.exe // To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS // and compile with -DPSAPI_VERSION=1void PrintProcessNameAndID( DWORD processID ) {TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");// Get a handle to the process.HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |PROCESS_VM_READ,FALSE, processID );// Get the process name.if (NULL != hProcess ){HMODULE hMod;DWORD cbNeeded;if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) ){GetModuleBaseName( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );}}// Print the process name and identifier._tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );// Release the handle to the process.CloseHandle( hProcess ); }int main( void ) {// Get the list of process identifiers.DWORD aProcesses[1024], cbNeeded, cProcesses;unsigned int i;if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){return 1;}// Calculate how many process identifiers were returned.cProcesses = cbNeeded / sizeof(DWORD);// Print the name and process identifier for each process.for ( i = 0; i < cProcesses; i++ ){if( aProcesses[i] != 0 ){PrintProcessNameAndID( aProcesses[i] );}}return 0; }http://msdn.microsoft.com/en-us/library/windows/desktop/ms682623%28v=vs.85%29.aspx
 
轉(zhuǎn)載于:https://my.oschina.net/plp626/blog/204303
總結(jié)
以上是生活随笔為你收集整理的windows api 枚举进程pid的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: h5 video全屏播放
- 下一篇: InnoDB文档笔记(三)—— Undo
