首先是一些简单的代码片段:
m_hProcessHandle = ::OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_CREATE_THREAD | PROCESS_DUP_HANDLE | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION), FALSE, m_dwProcessIdentifier);
if (NULL != m_hProcessHandle)
{
if (FALSE != ::OpenProcessToken(m_hProcessHandle, (TOKEN_QUERY | TOKEN_IMPERSONATE | TOKEN_DUPLICATE), &m_hImpersonizationToken))
{
wchar_t wszFullExecutableFileName[MAX_PATH];
if (0 == ::GetModuleBaseName(m_hProcessHandle, NULL, wszFullExecutableFileName, (sizeof(wszFullExecutableFileName)/sizeof(wchar_t))))
{
__DebugMessage(L"GetModuleBaseName() failed with GetLastError() = %d", ::GetLastError());
}
else
{
if (0 == ::GetModuleFileNameEx(m_hProcessHandle, NULL, wszFullExecutableFileName, (sizeof(wszFullExecutableFileName)/sizeof(wchar_t))))
{
__DebugMessage(L"GetModuleFileNameEx() failed with GetLastError() = %d", ::GetLastError());
}
else
{
m_strFullFileName = wszFullExecutableFileName;
}
}
}
}
OpenProcess()和OpenProcessToken ()一样返回一个有效的句柄,但是当我调用后续的GetModuleBaseName()和GetModuleFileNameEx()函数时,我得到GetLastError() = 6(句柄无效)。我在 Windows 7 上以管理员身份运行该代码。给出了什么?
干杯,GumbyTheBorg