Registriert seit: 1. Feb 2018
3.691 Beiträge
Delphi 11 Alexandria
|
AW: ProcessList stürzt ab nach kurzer zeit 64Bit
23. Aug 2018, 18:43
Delphi-Quellcode:
procedure TProcess.GetUserInformation;
type
PTokenUser = ^TTokenUser;
TTokenUser = record
User: TSIDAndAttributes;
end;
const
PROCESS_QUERY_LIMITED_INFORMATION = $1000;
var
vHandle: THandle;
vToken: THandle;
// vUserName: array [0 .. 255] of char;
// vDomainName: array [0 .. 255] of char;
vUserName, vDomainName: string;
vUserNameSize: DWORD;
vDomainNameSize: DWORD;
vTokenUser: PTokenUser;
vInfoSize: Cardinal;
vUse: SID_NAME_USE;
begin
FUser := '';
FDomain := '';
vHandle := OpenProcess(PROCESS_QUERY_INFORMATION, False, FID);
if vHandle > 0 then
try
if OpenProcessToken(vHandle, TOKEN_QUERY, vToken) then
try
GetTokenInformation(vToken, TokenUser, nil, 0, vInfoSize);
vUserNameSize := SizeOf(vUserName);
vDomainNameSize := SizeOf(vDomainName);
vUse := SidTypeUser;
GetMem(vTokenUser, vInfoSize);
try
if not GetTokenInformation(vToken, TokenUser, vTokenUser, vInfoSize, vInfoSize) then
raise ESystemError.Create;
vUserNameSize := 0;
vDomainNameSize := 0;
LookupAccountSid(nil, vTokenUser.User.Sid, nil, vUserNameSize, nil,
vDomainNameSize, vUse);
SetLength(vUserName, NamevUserNameSize);
SetLength(vDomainName, vDomainNameSize);
LookupAccountSid(nil, vTokenUser.User.Sid, PChar(vUserName), vUserNameSize, PChar(vDomainName),
vDomainNameSize, vUse);
// Result := PChar(vDomainName) + '/' + PChar(vUserName);
FUser := PChar(vUserName);
FDomain := PChar(vDomainName); // << Hier stürzt die Anwendung ab nur unter 64Bit.
finally
FreeMem(vTokenUser);
end;
finally
CloseHandle(vToken);
end;
finally
CloseHandle(vHandle);
end;
end;
Weis jemand warum ?
gruss
Ich habe mal den LookupAccountSid Teil angepasst, weiter oben stimmt nun etwas nicht wegen veränderung.... grrrr
|
|
Zitat
|