::GetWindowThreadProcessId(hWnd, &dwProcID);
     hProc = ::OpenProcess(PROCESS_VM_READ, true, dwProcID);
     ::ReadProcessMemory(hProc, (LPVOID)0x0045CB8C, (LPVOID)&obj->m_bInput, 4, NULL);
就上面的代码,用VC2005调试时能读出地址的值
可是不调试器直接运行可以发现
OpenProcess()返回为NULL,进程的dwProcID正确
为什么?

解决方案 »

  1.   

    To open a handle to another another process and obtain full access rights, you must enable the SeDebugPrivilege privilege
      

  2.   

    dwProcID = ::GetWindowThreadProcessId(hWnd, NULL);
    返回的是ProcessID,你传的地址是ThreadID
      

  3.   

    权限够的话,看看 OpenProcess 被钩了没有
      

  4.   


    void EnableDebugPriv()
    {
    HANDLE hToken;
    LUID sedebugnameValue;
    TOKEN_PRIVILEGES tkp; if ( ! OpenProcessToken( GetCurrentProcess(),
    TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
    return;
    if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) ){
    CloseHandle( hToken );
    return;
    }
    tkp.PrivilegeCount = 1;
    tkp.Privileges[0].Luid = sedebugnameValue;
    tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
    CloseHandle( hToken );
    }
    加入上面代码就行了