• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

WinXP, VC++, SDK. I need to TerminateProcess anyway. Help!

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

lex57ukr

Registered
Joined
Feb 27, 2004
Location
Orem, UT
I have UINT id of a process. With a call to OpenProcess(PROCESS_TERMINATE|SYNCHRONIZE, id) I should get its HANDLE for further use in calls to WaitForSingleObject and TerminateProcess. Everything is ok until I try to terminate a “hanging” process of a SYSTEM owner, i.e. the only thing I get is GetLastError() == 0x00000005 (access denied) instead of HANDLE to a process .

The system denies... I can guess the matters going on whatsoever. taskmgr.exe running under the same account (as my program) is able to shutdown this freakish process anyway. My application cannot do any such thing. I would appreciate everyone who saves my time with a simple hint.

Thanks. :)

PS this might be important: I use functions from tlhelp32.h for taking a snapshot of processes in order to find my target. A snapshot is still opened while I'm trying to gain access with permission to shut the process down.

Although, my code works fine with processes running under the same user account. I need to make a sequence of calls to adjust the privileges, I guess; but I wouldn’t like to waist a lot of time for the experiments like this. I’m tired.
 
not too tough to behold when it's done

Very well… looks like I’m not going to get any help at all. Here, downwards I give my solution that works.

In order to terminate a high-level process user’s process must be a debugger, i.e. possessing debugger’s level of privileges. There might be some other ideas on the point – I’ll be glad to know them.

As far as I think, I give this extraction from my project for you, lads… This code shows how to make your own process to become a debugger.

HANDLE hToken;

// Try to open this process's access token
if ( OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken) )
{
// Attempt to modify the "Debug" privilege
TOKEN_PRIVILEGES tp;

tp.PrivilegeCount = 1;
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);

tp.Privileges[0].Attributes = fEnable ? SE_PRIVILEGE_ENABLED : 0;
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
fOk = (GetLastError() == ERROR_SUCCESS);

CloseHandle(hToken);
}
 
Back