Hallo Chris,
manchmal liegt die Lösung doch näher als erwartet. Ich habe anstatt des Domains den Domainnamen verwendet.
Mit NetGetDCName(nil,pointer(DomainName),pointer(Domai n)); bekommt man die Domain heraus.
Für die, die es interessiert hier der ganze Code :
Delphi-Quellcode:
Function NetUserGetGroups(ServerName, UserName : lpWStr; Level : DWord; Var Buffer : Pointer; PrefMaxLen : DWord; EntriesRead, TotalEntries : lpDWord) : LongInt; stdcall; External 'NETAPI32.DLL';
procedure TForm1.Button3Click(Sender: TObject);
Type
USER_INFO_0 = Record
Group_Name : PWideChar;
End;
TBuffer = array[0..1024] of Pointer;
var
Level : DWORD;
PrefMaxLen :DWORD;
PAdr : DWord;
PBuffer : ^TBuffer;
Buffer:TBuffer;
entriesRead, totalEntries : DWORD;
ResultNetApiStatus :NetAPIStatus;
TheUser:Array[0..255] Of WideChar;
User_Info_0_Struct : USER_INFO_0;
i:Integer;
domain,DomainName : PWideChar;
begin
Level:=0;
PrefMaxLen:= 1024 ;
StringToWideChar(DomainNameEdit.text,@DomainName,255);
//get Domain Controller
NetGetDCName(nil,pointer(DomainName),pointer(Domain));
DomainEdit.Text:=WideCharToString(domain); // nur zur Ansicht
StringToWideChar(UserEdit.text,@TheUser,255);
UserGroupMemo.Clear;
ResultNetApiStatus:=NetUserGetGroups (domain,@TheUser, level, pointer(Pbuffer) , PrefMaxLen, @entriesRead, @totalEntries);
If ResultNetApiStatus = 0 Then Begin
For I := 0 To EntriesRead - 1 Do begin
User_Info_0_Struct := USER_INFO_0(PBuffer[i]);
UserGroupMemo.Lines.Add(WideCharToString(User_Info_0_Struct.Group_Name));
end;
if (Domain <> nil) then NetApiBufferFree(Domain);
if (pBuffer <> nil) then NetApiBufferFree(pBuffer);
End;
End;
[edit=Luckie]Delphi-Tags. Mfg, Luckie[/edit]