- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
function GetProcessUser(aPID: Cardinal; var aResult: string): Boolean;
type
PTOKEN_USER = ^TOKEN_USER;
_TOKEN_USER = record
User: TSidAndAttributes;
end;
TOKEN_USER = _TOKEN_USER;
var
cbBuf: Cardinal;
ptiUser: PTOKEN_USER;
snu: SID_NAME_USE;
hToken, hProcess: THandle;
UserSize, DomainSize: Cardinal;
bSuccess: Boolean;
sUser, sDomain: string;
begin
Result := False;
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION, False, aPID);
if hProcess <> 0 then
begin
if OpenProcessToken(hProcess, TOKEN_QUERY, hToken) then
begin
bSuccess := GetTokenInformation(hToken, TokenUser, nil, 0, cbBuf);
ptiUser := nil;
while (not bSuccess) and (GetLastError = ERROR_INSUFFICIENT_BUFFER) do
begin
ReallocMem(ptiUser, cbBuf);
bSuccess := GetTokenInformation(hToken, TokenUser, ptiUser, cbBuf, cbBuf);
end;
CloseHandle(hToken);
if not bSuccess then
Убило название. Дальше можете не читать.
http://www.programmersforum.ru/showthread.php?t=242541
guest 14.12.2013 10:40 # −2
Stertor 14.12.2013 21:36 # +1
LispGovno 14.12.2013 22:15 # −1
bormand 14.12.2013 22:23 # +1
> CloseHandle
> GetTokenInformation
Хардкорнейшее и чистейшее винапи, какой еще линь?
LispGovno 14.12.2013 22:53 # 0