Max Bolingbroke
2004-07-20 22:08:01 UTC
Hi
I'm trying to get the process ID that owns a given thread handle using
Delphi. After much digging, it turns out I can use
NtQueryInformationThread in ntdll to get this information, and I've done
this successfully. The problem is now that the handle being passed in
may not have the THREAD_QUERY_INFORMATION access right. After more
digging, I found that I could use DuplicateHandle to get a handle with
more rights. Done and done, but although the handle it returns looks
valid, NtQUeryInformation rejects my request with ERROR_ACCESS_DENIED :(
Thanks in advance for any help!
Max Bolingbroke
-----
function GetProcessIDOfThread(threadHandle: dword) : dword;
var
basicInformation : THREAD_BASIC_INFORMATION; // This is defined
OK - I know because a C program i wrote to do this with a fully
privileged thread handle works fine with the an equivalent definition
returnCode : dword;
error : dword;
temporaryHandle : dword;
begin
temporaryHandle := 0;
DuplicateHandle(GetCurrentProcess(), threadHandle,
GetCurrentProcess(), @temporaryHandle, THREAD_QUERY_INFORMATION, TRUE,
0); // temporaryHandle is shown as != 0 in the MessageBox, so I *assume*
this works
returnCode := ntQueryInformationThreadEP(temporaryHandle, 0,
@basicInformation, 28, nil);
MessageBox(0, PChar(IntToStr(temporaryHandle) + ' ' +
IntToStr(basicInformation.uniqueProcess) + ' ' + IntToStr(returnCode) +
' ' + IntToStr(GetLastError())), 'Debug: Temp + PID + Return Code +
GLE', 0); // this debugging messagebox tells me that I have a valid temp
handle, a nonsense uniqueProcess, a return code of ERROR_ACCESS_DENIED
and GLE = 0 (I don't think it works for Ntdll.dll functions called
directly anyway, but I thought it better to be safe..)
CloseHandle(temporaryHandle);
result := basicInformation.uniqueProcess;
end;
I'm trying to get the process ID that owns a given thread handle using
Delphi. After much digging, it turns out I can use
NtQueryInformationThread in ntdll to get this information, and I've done
this successfully. The problem is now that the handle being passed in
may not have the THREAD_QUERY_INFORMATION access right. After more
digging, I found that I could use DuplicateHandle to get a handle with
more rights. Done and done, but although the handle it returns looks
valid, NtQUeryInformation rejects my request with ERROR_ACCESS_DENIED :(
Thanks in advance for any help!
Max Bolingbroke
-----
function GetProcessIDOfThread(threadHandle: dword) : dword;
var
basicInformation : THREAD_BASIC_INFORMATION; // This is defined
OK - I know because a C program i wrote to do this with a fully
privileged thread handle works fine with the an equivalent definition
returnCode : dword;
error : dword;
temporaryHandle : dword;
begin
temporaryHandle := 0;
DuplicateHandle(GetCurrentProcess(), threadHandle,
GetCurrentProcess(), @temporaryHandle, THREAD_QUERY_INFORMATION, TRUE,
0); // temporaryHandle is shown as != 0 in the MessageBox, so I *assume*
this works
returnCode := ntQueryInformationThreadEP(temporaryHandle, 0,
@basicInformation, 28, nil);
MessageBox(0, PChar(IntToStr(temporaryHandle) + ' ' +
IntToStr(basicInformation.uniqueProcess) + ' ' + IntToStr(returnCode) +
' ' + IntToStr(GetLastError())), 'Debug: Temp + PID + Return Code +
GLE', 0); // this debugging messagebox tells me that I have a valid temp
handle, a nonsense uniqueProcess, a return code of ERROR_ACCESS_DENIED
and GLE = 0 (I don't think it works for Ntdll.dll functions called
directly anyway, but I thought it better to be safe..)
CloseHandle(temporaryHandle);
result := basicInformation.uniqueProcess;
end;