Einzelnen Beitrag anzeigen

Benutzerbild von Sherlock
Sherlock

Registriert seit: 10. Jan 2006
Ort: Offenbach
3.798 Beiträge
 
Delphi 12 Athens
 
#6

AW: Eindeutige Identifikation Domäne

  Alt 5. Aug 2015, 10:24
Merke gerade, daß man die Antwort nicht sieht, wenn man nicht von google kommt
Darum

Zitat:
by:Ferruccio AccalaiPosted on 2003-09-08 at 06:35:43ID: 9309353

From http://www.thedelphimagazine.com/samples/1577/1577.htm

» Listing 1: Using LookupAccountName and LookupAccountSid.
Delphi-Quellcode:
// GetAccountName. Looks up the account name of the security
// principal specified by SID
function GetAccountName(const System: string; Sid: PSID;
  var Name: string): Boolean;
var
  DomainSize, NameSize: Longword;
  R: LongBool;
  Domain: string;
  Use: TSidNameUse;
begin
  Result := False;
  NameSize := 0;
  DomainSize := 0;
  R := LookupAccountSid(PChar(System), Sid, nil, NameSize,
    nil, DomainSize, Use);
  if (not R) and (GetLastError = ERROR_INSUFFICIENT_BUFFER)
    then begin
    SetLength(Domain, DomainSize);
    SetLength(Name, NameSize);
    Result := LookupAccountSid(PChar(System), Sid, PChar(
      Name), NameSize, PChar(Domain), DomainSize, Use);
  end else
    RaiseLastOSError;
end;
// GetAccountSid. Looks up the Sid of the specified security
// principal. Caller must free Sid using FreeMem.
function GetAccountSid(const System, AccountName: string;
  var Sid: PSID): Boolean;
var
  DomainSize, SidSize: Longword;
  R: LongBool;
  Domain: string;
  Use: TSidNameUse;
begin
  Result := False;
  SidSize := 0;
  DomainSize := 0;
  R := LookupAccountName(PChar(System), PChar(AccountName),
    nil, SidSize, nil, DomainSize, Use);
  if (not R) and (GetLastError = ERROR_INSUFFICIENT_BUFFER)
    then begin
    SetLength(Domain, DomainSize);
    Sid := AllocMem(SidSize);
    Result := LookupAccountName(PChar(System),
      PChar(AccountName), Sid, SidSize, PChar(Domain),
      DomainSize, Use);
    if not Result then begin
      FreeMem(Sid);
      Sid := nil;
    end;
  end else
    RaiseLastOSError;
end;
Oliver
Geändert von Sherlock (Morgen um 16:78 Uhr) Grund: Weil ich es kann
  Mit Zitat antworten Zitat