Autor Beitrag
schitho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: So 17.08.03 16:58 
Hi,

wie kann ich unter W2000 die User ID (S-1-5-.....) des aktuellen Users ermitteln?

_________________
(Sorry! Leider ewiger Delphi-Neuling)
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 17.08.03 20:13 
Mal irgendwo geklaut ... :wink: ... keine Ahnung von wem:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function get_loggeduser_SID: string;
var
  Token: THandle;
begin
  if(Win32Platform = VER_PLATFORM_WIN32_NT) then begin
    if OpenProcessToken(GetCurrentProcess,TOKEN_QUERY,Token) then try
      Result := TokenToUserSidString(Token)
    finally
      CloseHandle(Token);
    end;
  end else
    Result := '';
end;
schitho Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 288

XP Home SP2
D2005 Prof
BeitragVerfasst: So 17.08.03 21:21 
Thanx!

Aber welche Uses muss ich einbinden, damit Delphi TokenToUserSidString kennt?

In meiner OH hab ich dazu nicht gefunden.

Ich hab zwischenzeitlich auch noch eine andere Lösung gefunden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
function GetSID : string;
// Liefert die User-ID (SID) unter NT/2000
var
  regist: TRegistry;
  SidList : TStrings;

begin
result:='';
if IsNT then
  begin
    SidList:=Tstringlist.create;
    regist:=TRegistry.Create;
    regist.RootKey:=HKEY_CURRENT_USER;
    regist.OpenKey('Software\Microsoft\Protected Storage System Provider', false);
    try
      regist.GetKeyNames(SidList);
    finally
      regist.free;
    end;
    result:=SidList[0];
    SidList.Free;
  end;
end;

_________________
(Sorry! Leider ewiger Delphi-Neuling)
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 17.08.03 22:41 
Upps. Jetzt weiß ich auch, von wem ich die Funktion ... äh ... habe ...
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
//
// (c) Nico Bendlin
//
function TokenToUserSidString(Token: THandle): string;
const
  SECURITY_NT_AUTHORITY = 5;
type
  PSID = ^TSID;
  TSID = packed record
    Revision: Byte;
    SubAuthorityCount: Byte;
    IdentifierAuthority: TSIDIdentifierAuthority;
    SubAuthority: array [Byte] of DWORD;  // [0..SubAuthorityCount - 1]
  end;
  PTokenUser = ^TTokenUser;
  TTokenUser = record
    User: TSIDAndAttributes;
  end;
var
  User: PTokenUser;
  Size: DWORD;
  Loop: Byte;
begin
  Result := '';
  Size := 4096;
  GetMem(User, Size);
  try
    FillChar(User^, Size, 0);
    if GetTokenInformation(Token, TokenUser, User, Size, Size) then
      with PSID(User^.User.Sid)^ do
      begin
        Result := 'S-' + IntToStr(Revision) + '-' +
          IntToStr(IdentifierAuthority.Value[SECURITY_NT_AUTHORITY]);
        for Loop := 0 to SubAuthorityCount - 1 do
          Result := Result + '-' + IntToStr(SubAuthority[Loop]);
      end;
  finally
    FreeMem(User);
  end;
end;

Das gehört noch dazu. Sorry. :oops: