Neha
Neha

Reputation: 1

OpenProcess fails for win 7

I am using OpenProcess function. The code works perfectly fine in windows XP but fails on win 7 X32 bit.

My code is as follows

void SetDebugPrivileges()
{
    void* tokenHandle;

    TOKEN_PRIVILEGES privilegeToken;
    LookupPrivilegeValue(0, SE_DEBUG_NAME, &privilegeToken.Privileges[0].Luid);
    privilegeToken.PrivilegeCount = 1;
    privilegeToken.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &tokenHandle);
    AdjustTokenPrivileges(tokenHandle, 0, &privilegeToken, sizeof(TOKEN_PRIVILEGES), 0, 0);
    CloseHandle(tokenHandle);
}

HANDLE _stdcall MyOpenProcess(DWORD dwAccess, BOOL bInherit, DWORD dwPID)
{
    SetDebugPrivileges();

   HANDLE hRes = OpenProcess(dwAccess | PROCESS_SET_INFORMATION | PROCESS_VM_READ, bInherit, dwPID);
}

OpenProcess fails with error code 5 on win 7 but works fine on XP. It would be great if anyone could help with this issue.

Upvotes: 0

Views: 2366

Answers (1)

Arnout
Arnout

Reputation: 2790

Most probably this is UAC-related. Are OpenProcessToken and AdjustTokenPrivileges actually successful?

Upvotes: 4

Related Questions