Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#1

ProcessList stürzt ab nach kurzer zeit 64Bit

  Alt 23. Aug 2018, 18:10
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;
  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;
            LookupAccountSid(nil, vTokenUser.User.Sid, @vUserName, vUserNameSize, @vDomainName,
              vDomainNameSize, vUse);
            FUser := vUserName;
            FDomain := 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
  Mit Zitat antworten Zitat