Das ist der entscheidende Code für dich:
Delphi-Quellcode:
class function TMachineCollection.GetAllMachines(const Domain: string; ExceptionMode: TExceptionMode):
TMachineCollection;
var
err : NET_API_STATUS;
bufPtr : Pointer;
si : Pointer;
entriesread : DWORD;
totalentries : DWORD;
resumehandle : DWORD;
pCurrent : PSERVER_INFO_100;
i : Integer;
Machine : TMachine;
Major : Integer;
Minor : Integer;
begin
Result := nil;
bufPtr := nil;
resumehandle := 0;
try
err := NetServerEnum(nil, 100, bufPtr, MAX_PREFERRED_LENGTH, entriesread, totalentries, SV_TYPE_NT or
SV_TYPE_WORKSTATION or SV_TYPE_SERVER or SV_TYPE_SERVER_NT, PWideChar(WideString(Domain)),
resumehandle);
if err = NERR_SUCCESS then
begin
Result := TMachineCollection.Create;
pCurrent := bufPtr;
for i := 0 to totalentries - 1 do
begin
Machine := TMachine.Create;
Machine.Machine := pCurrent.sv100_name;
Machine.IP := Machine.Machine;
err := NetWkStaGetInfo(PWideChar(WideString(Machine.Machine)), 101, si);
if err = NERR_Success then
begin
Major := PWKSTA_INFO_100(si)^.wki100_ver_major;
Minor := PWKSTA_INFO_100(si)^.wki100_ver_minor;
Machine.OS := Machine.OSIdToOSStr(Major, Minor);
end;
Machine.SetToD(GetRemoteToD(WideString(Machine.Machine)));
Result.Add(Machine);
Machine.LoggedOnUsers := TLoggedOnUserCollection.GetAllUsers(Machine.Machine, emOff);
Inc(pCurrent);
end;
end
else
raise ENetAPIError.Create(err);
finally
NetApiBufferFree(bufPtr);
end;
end;
Die gefundenen Rechner werden dann in einer Objektliste abgelegt.
Hätte man aber auch selber draufkommen könne, wenn man sich den Code mal etwas genauer angeguckt hätte.