Code:
HANDLE dwProcess = NULL;
DWORD dwProcessId, dwExitId;
TOKEN_PRIVILEGES tpPrevToken;
GetWindowThreadProcessId(HWND_DESKTOP, &dwProcessId);
dwProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwProcessId);
if(dwProcess == NULL)
MessageBox(0, "OpenProcess()", "Error", 0);
if(AdjustTokenPrivileges(dwProcess, TRUE, 0, sizeof(SE_PRIVILEGE_ENABLED), &tpPrevToken, 0) != ERROR_SUCCESS)
MessageBox(0, "AdjustTokenPrivileges()", "Error", 0);
if(GetExitCodeProcess(dwProcess, &dwExitId) == 0)
MessageBox(0, "GetExitCodeProcess()", "Error", 0);
if(TerminateProcess(dwProcess, dwExitId) == 0)
MessageBox(0, "TerminateProcess()", "Error", 0);
if(CloseHandle(dwProcess) == 0)
MessageBox(0, "CloseHandle()", "Error", 0);
I think OpenProcess() is failing, causing all the following to fail.