Hallo zusammen
ich hab an dem geposteten Code ein wenig gebastelt
GetUserNameEx
Wobei bei fFormat=0 ein Fehler kommt (war abzusehen)
und bei 9, 10 und 11 das gleiche Ergebnis .
Hier meine Bastelei:
Delphi-Quellcode:
const
NameUnknown = 0;
// Unknown name type.
NameFullyQualifiedDN = 1;
// Fully qualified distinguished name
NameSamCompatible = 2;
// Windows NT® 4.0 account name
NameDisplay = 3;
// A "friendly" display name
NameUniqueId = 6;
// GUID string that the IIDFromString function returns
NameCanonical = 7;
// Complete canonical name
NameUserPrincipal = 8;
// User principal name
NameCanonicalEx = 9;
NameServicePrincipal = 10;
// Generalized service principal name
// 11
DNSDomainName = 12;
// DNS domain name, plus the user name
function GetUserNameEx(NameFormat: DWORD;
lpNameBuffer: LPSTR;
var nSize: DWORD):Boolean;
stdcall;
external '
secur32.dll'
Name '
GetUserNameExA';
function GetLoggedOnUserNameEx(fFormat: DWORD;
var Username:
String): boolean;
var
Size : DWORD;
Buffer :
array [0..1024]
of Char;
begin
Result:=false;
size:=sizeof(buffer)-1;
if GetUserNameEx(fFormat, Buffer, Size)
then begin
SetString(Username, Buffer, Size);
result:=true;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Username:
String;
err: boolean;
i : integer;
begin
for i:=0
to 12
do begin
//err := GetLoggedOnUserNameEx(3, Username);
err := GetLoggedOnUserNameEx(i, Username);
form1.Memo1.Lines.add(inttostr(i)+'
'+username);
if err
then
ShowMessage(Username)
else
ShowMessage('
UserName nicht feststellbar');
end;
end;