Hi.
Please help me what's wrong.
Below is the code that scans the local network.
Everything in {} is my experiments (unsuccessful)
Result
i: 0
i: 0 i2: 0
i: 0 i2: 1 Microsoft Terminal Services
i: 0 i2: 2 Microsoft Windows Network
i: 1 Microsoft Terminal Services
i: 2 Microsoft Windows Network
Please help me what's wrong.
Below is the code that scans the local network.
Everything in {} is my experiments (unsuccessful)
Result
i: 0
i: 0 i2: 0
i: 0 i2: 1 Microsoft Terminal Services
i: 0 i2: 2 Microsoft Windows Network
i: 1 Microsoft Terminal Services
i: 2 Microsoft Windows Network
Code:
procedure TForm1.Button16Click(Sender: TObject);
Type
PNRArr = ^TNRArr;
TNRArr = array[0..512] of TNetResourceW;
var Result1,Result2,Result3,Result4,EntrReq,EntrReq2,SizeReq,SizeReq2: Cardinal;
twx,twx2: NativeUInt;
x,x2: array[1..MaxEntries] of TNetResource;{PNRArr;}{PNETRESOURCE;}
i,i2:integer;
//Network,Network2: TNetResource;
begin
{ FillChar(Network, SizeOf(Network), 0);
with Network do
begin
dwScope := RESOURCE_GLOBALNET;
dwType := RESOURCETYPE_ANY;
dwUsage := RESOURCEUSAGE_CONTAINER;
end;}
Result1 :=WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, RESOURCEUSAGE_CONTAINER, nil{@Network}, twx);
case Result1 of
0: begin
//showmessage('WNetOpenEnum NO_ERROR '+twx.ToString);
if twx<>0 then
begin
//New(x);
SizeReq := {16384}SizeOf(x);
EntrReq := Cardinal(-1);
//x := PNETRESOURCE(GlobalAlloc(GPTR, SizeReq));
Result2 := WNetEnumResource(twx, EntrReq, @x, SizeReq);
case Result2 of
NO_ERROR:
begin
//showmessage('WNetEnumResource NO_ERROR '+EntrReq.ToString);
For i := 0 To EntrReq - 1 do
begin
RichEdit1.Lines.Add('i: '+i.ToString+' '+x[i].lpRemoteName);
Result3 := WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, {RESOURCEUSAGE_CONTAINER}0, @x[i], twx2);
case Result3 of
NO_ERROR:
begin
//showmessage('i: '+i.ToString+' WNetOpenEnum2 NO_ERROR '+twx2.ToString);
SizeReq2 := SizeOf(x2);
EntrReq2 := Cardinal(-1);
Result4 := WNetEnumResource(twx2, EntrReq2, @x2, SizeReq2);
case Result4 of
NO_ERROR:
begin
//showmessage('i: '+i.ToString+' WNetEnumResource2 NO_ERROR '+EntrReq2.ToString);
For i2 := 0 To EntrReq2 - 1 do
begin
RichEdit1.Lines.Add('i: '+i.ToString+' i2: '+i2.ToString+' '+x2[i2].lpRemoteName);
end;
end;
{ERROR_NO_NETWORK: showmessage('i: '+i.ToString+' WNetEnumResource2 ERROR_NO_NETWORK '+EntrReq2.ToString);}
else showmessage('i: '+i.ToString+' Result4: '+Result4.ToString+' WNetEnumResource2 '+EntrReq2.ToString);
end;
WNetCloseEnum(twx2);
end;
{1222: showmessage('i: '+i.ToString+' WNetOpenEnum2 ERROR_NO_NETWORK '+twx2.ToString);
else showmessage('i: '+i.ToString+' Result3: '+Result3.ToString+' WNetOpenEnum2 '+EntrReq2.ToString);}
end;
end;
WNetCloseEnum(twx);
end;
{ERROR_NO_NETWORK: showmessage('WNetEnumResource ERROR_NO_NETWORK '+EntrReq.ToString);
else showmessage('Result2: '+Result2.ToString+' WNetEnumResource '+EntrReq.ToString);}
end;
end;
end;
{1222: showmessage('WNetOpenEnum ERROR_NO_NETWORK '+twx.ToString);
else showmessage('Result1: '+Result1.ToString+' WNetOpenEnum '+EntrReq.ToString);}
end;
//WNetCloseEnum(twx);
end;