type
NET_DISPLAY_MACHINE =
record
usri2_name : PWideChar;
usri2_comment : PWideChar;
usri2_flags : Cardinal;
usri2_user_id : Cardinal;
usri2_next_index : Cardinal;
end;
PNET_DISPLAY_MACHINE = ^NET_DISPLAY_MACHINE;
const
NERR_Success = 0;
ERROR_MORE_DATA = 234;
function NetQueryDisplayInformation(ServerName: PWideChar;
Level,
Index, EntriesRequested,
ReferredMaximumLength: Cardinal;
var ReturnedEntryCount: Cardinal;
var SortedBuffer: Pointer): Cardinal;
stdcall;
external '
Netapi32.dll';
function NetApiBufferFree(Buffer : Pointer): Cardinal;
stdcall;
external '
NETAPI32.dLL';
function ListComputerAccounts(sServerName: PWideChar; Output:TStrings):integer;
var
total, res, count,
index: Cardinal;
sBuffer: Pointer;
ComputerAccounts: PNET_DISPLAY_MACHINE;
begin
Output.clear;
index := 0;
res := 0;
repeat
res := NetQueryDisplayInformation(sServerName, 2,
index, 100, High(Cardinal), total, sBuffer);
showmessage(inttostr(res));
if (res = NERR_Success)
or (res=ERROR_MORE_DATA)
then
begin
ComputerAccounts := @sBuffer^;
while total > 0
do
begin
Output.Add(StringReplace(
String(ComputerAccounts^.usri2_name), '
$', '
', [rfReplaceAll]));
index := ComputerAccounts^.usri2_next_index;
Dec(total);
inc(ComputerAccounts);
end;
end;
NetApiBufferFree(sBuffer);
until res <> ERROR_MORE_DATA;
end;