![]() |
PSID in String umwandeln
Hi ihrs kann mir mal grade jemand ein kurzes Beispiel Poasten, wie ich aus einer PSID einen String mache???
Vielen Dank schon mal |
Re: PSID in String umwandeln
Es gibt da die API ConvertSidToStringSid:
Code:
gibts aber erst ab Win2000
BOOL ConvertSidToStringSid(
PSID Sid, LPTSTR* StringSid ); aber es findet sich auch noch ein Code-Schnipsel im PSDK:
Code:
BOOL GetTextualSid(
PSID pSid, // binary SID LPTSTR TextualSid, // buffer for Textual representation of SID LPDWORD lpdwBufferLen // required/provided TextualSid buffersize ) { PSID_IDENTIFIER_AUTHORITY psia; DWORD dwSubAuthorities; DWORD dwSidRev=SID_REVISION; DWORD dwCounter; DWORD dwSidSize; // Validate the binary SID. if(!IsValidSid(pSid)) return FALSE; // Get the identifier authority value from the SID. psia = GetSidIdentifierAuthority(pSid); // Get the number of subauthorities in the SID. dwSubAuthorities = *GetSidSubAuthorityCount(pSid); // Compute the buffer length. // S-SID_REVISION- + IdentifierAuthority- + subauthorities- + NULL dwSidSize=(15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR); // Check input buffer length. // If too small, indicate the proper size and set last error. if (*lpdwBufferLen < dwSidSize) { *lpdwBufferLen = dwSidSize; SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; } // Add 'S' prefix and revision number to the string. dwSidSize=wsprintf(TextualSid, TEXT("S-%lu-"), dwSidRev ); // Add SID identifier authority to the string. if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) ) { dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid), TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"), (USHORT)psia->Value[0], (USHORT)psia->Value[1], (USHORT)psia->Value[2], (USHORT)psia->Value[3], (USHORT)psia->Value[4], (USHORT)psia->Value[5]); } else { dwSidSize+=wsprintf(TextualSid + lstrlen(TextualSid), TEXT("%lu"), (ULONG)(psia->Value[5] ) + (ULONG)(psia->Value[4] << 8) + (ULONG)(psia->Value[3] << 16) + (ULONG)(psia->Value[2] << 24) ); } // Add SID subauthorities to the string. // for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++) { dwSidSize+=wsprintf(TextualSid + dwSidSize, TEXT("-%lu"), *GetSidSubAuthority(pSid, dwCounter) ); } return TRUE; } |
Re: PSID in String umwandeln
In welcher Unit ist denn die Function deklariert???
Hab mal im Internet gesucht und die meinten:
Delphi-Quellcode:
aber die hab ich leider nich :wall:
You can use the function ConvertSidToStringSid, declared in NTCommon.pas
Kann mir mal jemand nen Link senden unterdem ich die finde??? (Bei Torry hab ich se ned gefunden) Vielen Dank |
Re: PSID in String umwandeln
Hab mir das mal aus VB in Delphi übersetzt:
VB:
Delphi-Quellcode:
Delphi
Function ConvertSidToStringSid Lib "advapi32.dll" Alias "ConvertSidToStringSidA" ( _
ByVal Sid As Long, _ StringSid As Long _ ) As Long
Delphi-Quellcode:
Aber ist es geht trozdem nicht.
function ConvertSidToStringSidA(ByVal, StringSid: Longint): Longint; stdcall;external 'advapi32.dll';
Was hab ich falsch gemacht??? |
Re: PSID in String umwandeln
Hi,
gehe ich recht in der Annahme, das es sich bei der PSID um eine Guid handelt, dann stellt Delphi die Funktion guidToSting in der Unit SysUtils zur Verfügung Grüss Woki |
Re: PSID in String umwandeln
Zitat:
|
Re: PSID in String umwandeln
Hab mir jetzt mal eine eigene Procedure geschrieben um alle Benutzernamen + deren SIDs zu erhalten (Bin aber noch ein totaler Anfänger also erwartet jetzt nix!). List nur die Werte aus der Registry aus.
Die Procedure
Delphi-Quellcode:
Der Aufruf
procedure GetUsersAndSIDs(var Users,Sids:TStringList);
var reg : Tregistry; KeyNames:TstringList; i:integer; begin Users.Clear; Sids.Clear; KeyNames:=TstringList.Create; Reg:=Tregistry.Create; reg.RootKey:=HKEY_USERS; reg.OpenKey('',false); reg.GetKeyNames(KeyNames); i:=KeyNames.Count-1; while i>=1 do begin reg.CloseKey; if (reg.KeyExists(KeyNames.Strings[i]+'\Software\Microsoft\Windows\CurrentVersion\Explorer')) and not((KeyNames.Strings[i]='.DEFAULT')or not((KeyNames.Strings[i][Length(KeyNames.Strings[i])]<>'s')and(KeyNames.Strings[i][Length(KeyNames.Strings[i-1])]<>'e'))) then begin reg.OpenKey(KeyNames.Strings[i]+'\Software\Microsoft\Windows\CurrentVersion\Explorer',false); if reg.ValueExists('Logon User Name') then begin if reg.ReadString('Logon User Name')<>'' then begin Sids.Add(KeyNames.Strings[i]); Users.Add(reg.ReadString('Logon User Name')); end; end; end; i:=i-1; end; end;
Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var Users,Sids:TStringList; begin Users:=TStringList.Create; Sids:=TStringList.Create; GetUsersAndSIDs(Users,Sids); Listbox1.Items:=Users; Listbox2.Items:=Sids; FreeAndNil(Users); FreeAndNil(Sids); end; |
Re: PSID in String umwandeln
Moin SleepyMaster,
Zitat:
|
Re: PSID in String umwandeln
Joahr! Dann geht ed! Aber ich hab meine eigene Procedure jetzt schon in mein Programm eingebaut.
|
Re: PSID in String umwandeln
Ahhhhhhhhhhhhhhhhh!!! :wall: :wall: :wall: :wall: :wall: :wall: :wall:
Das andere geht auch!!! (SysUtils) Wenn man anstelle von Zitat:
|
Re: PSID in String umwandeln
Nun ja,
für Tippfehler übernehme ich natürlich keine Gewähr, im Zweifelsfall helfen da aber Programmierhlfe und Teilstringfähigkeiten der Online - Hilfe weiter. Grüsse Woki |
Re: PSID in String umwandeln
Eine PSID ist ein Pointer auf eine SID und eine SID ist nunmal was ganz anderes als eine GUID!
Die beiden Funktionen zum Konvertieren der SIDs sind IMHO in den Delphi-Übersetzungen der Headers noch nicht importiert, das musst du selbst machen, die korrekte Übersetzung schaut so aus:
Delphi-Quellcode:
Ansonsten könntest du dir noch die oben gepostete Funktion aus dem SDK nach Delphi übersetzen...
function ConvertSidToStringSid(Sid: PSID; StringSid: PChar): Boolean; stdcall; external 'advapi32.dll';
PS: du musst die ganzen Sachen nicht aus der Registry einlesen, es gibt auch die entsprechneden APIs! ;) Aber das ganze Thema ist etwas komplexer... |
Re: PSID in String umwandeln
Yepp,
da hab ich wohl was verwechselt, Trotzdem ist meine Aussage nach den Regeln der Logik voll korrekt: Wenn PSID eine Guid ist (wäre), dann ... :-D :-D :-D :-D |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:46 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz