Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi PSID in String umwandeln (https://www.delphipraxis.net/11477-psid-string-umwandeln.html)

SleepyMaster 7. Nov 2003 14:15


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

Motzi 7. Nov 2003 19:27

Re: PSID in String umwandeln
 
Es gibt da die API ConvertSidToStringSid:
Code:
BOOL ConvertSidToStringSid(
  PSID Sid,
  LPTSTR* StringSid
);
gibts aber erst ab Win2000

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;
}

SleepyMaster 8. Nov 2003 09:41

Re: PSID in String umwandeln
 
In welcher Unit ist denn die Function deklariert???

Hab mal im Internet gesucht und die meinten:

Delphi-Quellcode:
You can use the function ConvertSidToStringSid, declared in NTCommon.pas
aber die hab ich leider nich :wall:

Kann mir mal jemand nen Link senden unterdem ich die finde???
(Bei Torry hab ich se ned gefunden)

Vielen Dank

SleepyMaster 8. Nov 2003 09:47

Re: PSID in String umwandeln
 
Hab mir das mal aus VB in Delphi übersetzt:

VB:
Delphi-Quellcode:
Function ConvertSidToStringSid Lib "advapi32.dll" Alias "ConvertSidToStringSidA" ( _
    ByVal Sid As Long, _
    StringSid As Long _
    ) As Long
Delphi
Delphi-Quellcode:
function ConvertSidToStringSidA(ByVal, StringSid: Longint): Longint; stdcall;external 'advapi32.dll';
Aber ist es geht trozdem nicht.

Was hab ich falsch gemacht???

woki 8. Nov 2003 10:45

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

SleepyMaster 8. Nov 2003 11:05

Re: PSID in String umwandeln
 
Zitat:

...dann stellt Delphi die Funktion guidToSting in der Unit SysUtils zur Verfügung
Macht mein Delphi (7) leider nich! :wall:

SleepyMaster 8. Nov 2003 11:15

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:
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;
Der Aufruf
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;

Christian Seehase 8. Nov 2003 11:44

Re: PSID in String umwandeln
 
Moin SleepyMaster,

Zitat:

Zitat von SleepyMaster
Zitat:

...dann stellt Delphi die Funktion guidToSting in der Unit SysUtils zur Verfügung
Macht mein Delphi (7) leider nich! :wall:

Ich denke mal, wenn Du die Unit COMOBJ mit einbindest schon ;-)

SleepyMaster 8. Nov 2003 12:16

Re: PSID in String umwandeln
 
Joahr! Dann geht ed! Aber ich hab meine eigene Procedure jetzt schon in mein Programm eingebaut.

SleepyMaster 8. Nov 2003 12:19

Re: PSID in String umwandeln
 
Ahhhhhhhhhhhhhhhhh!!! :wall: :wall: :wall: :wall: :wall: :wall: :wall:

Das andere geht auch!!! (SysUtils)

Wenn man anstelle von

Zitat:

guidToSting
das mal richtig schreibt und guidToString nimmt


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:17 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz