timus221

Untitled

Mar 4th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <tchar.h>
  5. #include <psapi.h>
  6. // To ensure correct resolution of symbols, add Psapi.lib to TARGETLIBS
  7. // and compile with -DPSAPI_VERSION=1
  8.  
  9. void PrintProcessNameAndID(DWORD processID)
  10. {
  11. TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
  12.  
  13. // Get a handle to the process.
  14.  
  15. HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
  16. PROCESS_VM_READ,
  17. FALSE, processID);
  18.  
  19. // Get the process name.
  20.  
  21. if (NULL != hProcess)
  22. {
  23. HMODULE hMod;
  24. DWORD cbNeeded;
  25.  
  26. if (EnumProcessModules(hProcess, &hMod, sizeof(hMod),
  27. &cbNeeded))
  28. {
  29. GetModuleBaseName(hProcess, hMod, szProcessName,
  30. sizeof(szProcessName) / sizeof(TCHAR));
  31. }
  32. }
  33.  
  34. // Print the process name and identifier.
  35.  
  36. _tprintf(TEXT("%s (PID: %u)\n"), szProcessName, processID);
  37.  
  38. // Release the handle to the process.
  39.  
  40. CloseHandle(hProcess);
  41. }
  42.  
  43. int _tmain(int argc, _TCHAR* argv[])
  44. {
  45. // Get the list of process identifiers.
  46.  
  47. DWORD aProcesses[1024], cbNeeded, cProcesses;
  48. unsigned int i;
  49.  
  50. if (!EnumProcesses(aProcesses, sizeof(aProcesses), &cbNeeded))
  51. {
  52. return 1;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment