Board index » delphi » how to get list of computers of NT

how to get list of computers of NT

Hi

Does anyone know how to get a list of a machine names of an NT network.
I have used the shellbrowseforfolder thing, but it doesn't return a machine
name.

How do i do this??

Please also post to gsb97@doc

Thanks in advance !!

--
Gurpal Singh Bhachu,
Department of Computing,
Imperial College,
180 Queen's Gate,
London SW7

 

Re:how to get list of computers of NT


Try this. It is a cut out of one of my programs. The key information here is
the WNetEnumResource API call
Most of this was taken right out of  DevelopersHREF.

function TNetQueryThread.EnumerateNodes(lpnr: PNetResource): Boolean;
 var dwResult, dwResultEnum: Cardinal;
     hEnum: THandle;
     lpnrLocal: Pointer;
     lpnrLocalc: PNetResource;
     i: Integer;
     Comment, LocalName, RemoteName, Provider: String;
     dwScope, dwType, dwDisplayType, dwUsage: Cardinal;
     cbBuffer: Cardinal;
     cEntries: Cardinal;
     cEnum : Cardinal;

 begin
      Result:=False;
      cbBuffer:=16384;
      cEntries:=$FFFFFFFF;

      dwResult:=WNetOpenEnum(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,lpnr,hEnum);

      if dwResult<>NO_ERROR
      then begin
           ShowMessage('Error on WNetOpenEnum!');
           Exit;
      end;
      lpnrLocal:=AllocMem(cbBuffer);
      repeat

      dwResultEnum:=WNetEnumResource(hEnum,cEntries,lpnrLocal,cbBuffer);
      if dwResultEnum=NO_ERROR
      then begin
           for i:=0 to cEntries do
           begin
           lpnrLocalc:=Pointer(i*SizeOf(lpnrLocalc^)+Cardinal(lpnrLocal));
           dwScope:=lpnrLocalc^.dwScope;
           ltbDisplay:=lpnrLocalc^.lpRemoteName;
           dwType:=lpnrLocalc^.dwType;
           ltbDisplay:=ltbDisplay+' - '+IntToStr(dwType)+' - ';
           case dwType of
           0 : ltbDisplay:=ltbDisplay+'Server';
           1 : ltbDisplay:=ltbDisplay+'Share';
           2 : ltbDisplay:=ltbDisplay+'Printer';
           else ltbDisplay:=ltbDisplay+'Unknown';
           end;
           dwDisplayType:=lpnrLocalc^.dwDisplayType;
           if ((lpnrLocalc^.dwScope and RESOURCE_GLOBALNET)=RESOURCE_GLOBALNET)
and
              (lpnrLocalc^.dwType<>RESOURCEDISPLAYTYPE_GENERIC)
           then dwUsage:=lpnrLocalc^.dwUsage
           else dwUsage:=0;

           Comment:=lpnrLocalc^.lpComment;
           LocalName:=lpnrLocalc^.lpLocalName;
           RemoteName:=lpnrLocalc^.lpRemoteName;
           Provider:=lpnrLocalc^.lpProvider;
           ltbDisplay:=ltbDisplay+' - '+Comment;

           if (Copy(RemoteName, 1, 2)='\\') and (dwType = 0)then
           begin
           {===> fill list box}
           //TempList.Add(Copy(ltbDisplay,3,Length(ltbDisplay)));
           synchronize(FillListBox);
           //showmessage( Copy(ltbDisplay,3,Length(ltbDisplay)));
           end;
           if (lpnrLocalc^.dwUsage and
           RESOURCEUSAGE_CONTAINER)=RESOURCEUSAGE_CONTAINER
           then EnumerateNodes(lpnrLocalc);
           end;
           end
           else begin
           if dwResultEnum<>ERROR_NO_MORE_ITEMS
           then begin
                //ShowMessage('WNetEnumResource-error');
                Break;
           end;

           end;
      until dwResultEnum=ERROR_NO_MORE_ITEMS;

      FreeMem(lpnrLocal, cbBuffer);
      dwResult:=WNetCloseEnum(hEnum);

      if dwResult<>NO_ERROR
      then begin
           //ShowMessage('WNetCloseEnum-error');
           Result:=False;
      end
      else Result:=True;

end;

Quote
Gurpal Singh Bhachu wrote:
> Hi

> Does anyone know how to get a list of a machine names of an NT network.
> I have used the shellbrowseforfolder thing, but it doesn't return a machine
> name.

> How do i do this??

> Please also post to gsb97@doc

> Thanks in advance !!

> --
> Gurpal Singh Bhachu,
> Department of Computing,
> Imperial College,
> 180 Queen's Gate,
> London SW7

Other Threads