unit Unit1;
interface
uses Windows;
implementation
function RechnerInWG(lpnr: PNetResource): Boolean;
procedure AddComputerToList(Value: TNetResource);
var strRemoteName:
String;
begin
strRemoteName := Value.lpRemoteName;
if Value.dwDisplayType <> RESOURCEDISPLAYTYPE_SERVER
THEN Exit;
ListBox.Items.Add(strRemoteName);
end;
const
// RESOURCE_CONNECTED RESOURCE_CONTEXT RESOURCE_GLOBALNET RESOURCE_REMEMBERED
c_dwScope = RESOURCE_GLOBALNET;
// RESOURCETYPE_ANY RESOURCETYPE_DISK RESOURCETYPE_PRINT
c_dwType = RESOURCETYPE_DISK;
var cbBuffer: DWORD;
hEnum, dwResult, dwResultEnum : DWORD;
lpnrLocal :
array [0..16384
div SizeOf(TNetResource)]
of TNetResource;
i : Integer;
cEntries : Longint;
begin
//
// basiert auf Microsoft Beispiel "Enumerating Network Resources" in C++
//
// [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wnet/networks_77sj.asp[/url]
//
cbBuffer := 16384;
centries := -1;
dwResult := WNetOpenEnum( c_dwScope,
c_dwType,
0,
// 0 = All resources
lpnr,
hEnum);
if dwResult <> NO_ERROR
then
begin
Result := False;
// Fehlerbehandlung('Fehler bei WNetOpenEnum (%d)',[dwResult]);
Exit;
end;
FillChar( lpnrLocal, cbBuffer, 0 );
dwResultEnum := WNetEnumResource(hEnum,
DWORD(cEntries),
@lpnrLocal,
cbBuffer);
if dwResultEnum = NO_ERROR
then
begin // dwResultEnum = NO_ERROR
for i := 0
to cEntries - 1
do
begin
AddComputerToList(lpnrLocal[i]);
if (c_dwScope = RESOURCE_GLOBALNET)
AND
(RESOURCEUSAGE_CONTAINER = (lpnrLocal[i].dwUsage
AND RESOURCEUSAGE_CONTAINER))
then RechnerInWG(@lpnrLocal[i]);
end;
end // dwResultEnum = NO_ERROR
else
begin // dwResultEnum <> NO_ERROR
IF dwResultEnum <> ERROR_NO_MORE_ITEMS
THEN
begin
Result := False;
// Fehlerbehandlung (Format('Fehler bei WNetEnumResource (%d)',[dwResultEnum]));
Exit;
end;
end;
// dwResultEnum <> NO_ERROR
dwResult := WNetCloseEnum(hEnum);
if dwResult <> NO_ERROR
then
begin
Result := False;
// Fehlerbehandlung (Format('Fehler bei WNetCloseEnum (%d)',[dwResult]));
Exit;
end;
Result := True;
end;
end.