Fórum Computadores da Rede #207469

19/01/2004

0

Eu preciso de uma rotina para localizar e mostrar todos os computadores da rede (e que funcione também no Windows XP).


Fabioavallone

Fabioavallone

Responder

Posts

20/01/2004

Anisio

Eu também tenho este problema...
por favor, alguém responda a nossa dúvida :D


Responder

Gostei + 0

20/01/2004

Anisio

Por favor alguém me ajude..

to precisando ta rotina...naum encontro em lugar nenhum


Responder

Gostei + 0

21/01/2004

Anisio

Achei o código, penei mas achei :D

Ta aí Fabio, espero q funcione no XP (no 98 funciona)
soh coloque um TreeView no form

procedure TUserNet.GetNetwork(it:TTreeNode; lpNetResource:PNetResourceA);
type
  PNetResourceArray = ^TNetResourceArray;
  TNetResourceArray = array[0..MaxInt div SizeOf(TNetResource) - 1] of TNetResource;
var neh,cnt,size:cardinal;
    netres:integer;
    res:PNetResourceArray;
    i:integer;
    s:string;
    itc:TTreeNode;
begin
   { Inicializando Variáveis }
   cnt := $FFFFFFFF;
   Size := 50 * SizeOf(TNetResource);
   { Abre a enumeração }
   if WNetOpenEnum(RESOURCE_CONTEXT, RESOURCETYPE_DISK, 0, lpNetResource, neh) = NO_ERROR then
   try
      { Alocando Memória }
      GetMem(Res, Size);
      { Buscar os recursos da net }
      netres := WNetEnumResource(neh, cnt, res, size);
      { Se houver erro }
      if netres = NO_ERROR then
      begin
         { If not browse through the fetxhed net resources }
         for i := 0 to cnt - 1 do
            { Controlling if usage is not a network share }
            if not (res^[i].dwUsage in [1,5]) then
            begin
               { Since the name includes full path we have to cut the path off }
               s := copy(res^[i].lpRemoteName, lastdelimiter(´´, res^[i].lpRemoteName) + 1,
                length(res^[i].lpRemoteName));
               { If we are in the root }
               if lpnetresource = nil then
                  { Set the TreeNode to the root. This skips the ´Microsoft Windows Network´
                    node and goes directly to the list of workgroups and domains }
                  itc := it
               else
                  { Add a child to the selected TreeNode }
                  itc := trvNetwork.Items.AddChild(it, s);
               { Call the procedure for the actual net resource }
               GetNetwork(itc, @res^[i]);
            end;
      end;
   finally
      { Freeing memory }
      FreeMem(Res, Size);
   end;
   { Closing the enumeration }
   WNetCloseEnum(neh);
end;

{ Filling the TreeView when creating the form }
procedure TUserNet.FormCreate(Sender: TObject);
begin
   GetNetwork(nil,nil);
   TrVnetwork.FullExpand;
   TrVnetwork.Selected := TrVnetwork.Items[0];
end;



Responder

Gostei + 0

05/07/2015

Eraldo Bezerra

Ola tentei usar esse codigo, porem da erro na linha
{ Add a child to the selected TreeNode }
itc := trvNetwork.Items.AddChild(it, s);

que ha?
Responder

Gostei + 0

05/07/2015

Rodrigo Oliveira

Para que serve essa função/funcionalidade?
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar