Windows_31_procbase Process Fundamentals

Source: Internet
Author: User

Windows_31_procbase Process Basics
  
 
  1. // windows_31_ProcBase.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include <windows.h>
  5. #include <psapi.h> //另一块进程操作API
  6. void ProcModule( )
  7. {
  8. printf( "All Modules:\n" );
  9. //当前进程句柄
  10. HANDLE hProc = GetCurrentProcess( );
  11. //获取模块句柄
  12. HMODULE hModules[256] = { 0 };
  13. DWORD nNeed = 0;
  14. EnumProcessModules( hProc,hModules,256,&nNeed);
  15. //计算获取到句柄数量
  16. DWORD nCount = nNeed / sizeof( HMODULE );
  17. //打印句柄
  18. for (DWORD nIndex = 0; nIndex < nCount;nIndex++)
  19. {
  20. //获取各模块所对应的文件名和路径
  21. CHAR szPath[MAX_PATH] = { 0 };
  22. GetModuleFileNameEx( hProc, hModules[nIndex], szPath, MAX_PATH );
  23. printf( "\t%d: %p, %s\n", nIndex + 1, hModules[nIndex] ,szPath);
  24. }
  25. }
  26. void ProcInfo( )
  27. {
  28. //获取进程ID
  29. DWORD nID = GetCurrentProcessId( );
  30. //获取进程句柄(-1,伪句柄)
  31. HANDLE hProc = GetCurrentProcess( );
  32. printf( "Process ID: %d\n", nID );
  33. printf( "Process Handle: %p\n", hProc );
  34. //根据进程ID获取进程实际句柄
  35. hProc = OpenProcess( PROCESS_ALL_ACCESS, FALSE, nID );
  36. printf( "Process Handle: %p\n", hProc );
  37. }
  38. int _tmain(int argc, _TCHAR* argv[])
  39. {
  40. ProcInfo( );
  41. ProcModule( );
  42. return 0;
  43. }



From for notes (Wiz)

Windows_31_procbase Process Fundamentals

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.