[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Get the list of computer names from windows network neighbour hood

Posted on 2002-07-01
2
Medium Priority
?
207 Views
Last Modified: 2010-04-04
Hai experts,

How do we get the list of computer names which are displayed in the network neighbourhood, programatically.
0
Comment
Question by:pradeep_pc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 7121505
Look in the UDDF (http://www.gnomehome.demon.nl/uddf/) Networking Section.
0
 
LVL 2

Accepted Solution

by:
mikepj earned 150 total points
ID: 7123617
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm2 = class(TForm)
    Memo1: TMemo;
    procedure DisplayStruct(lpnr : PNETRESOURCE);
    function EnumerateFunc(lpnr : PNETRESOURCE) : Boolean;
    procedure NetErrorHandler(
       dwResult  : DWORD;
       const Msg : String);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.DFM}


procedure TForm2.DisplayStruct(lpnr : PNETRESOURCE);
var
    p : PChar;
begin
    p := lpnr^.lpRemoteName;
    if (p[0] = '\') and (p[1] = '\') then
        p := p + 2;
    memo1.lines.Add(p);
    Caption := IntToStr(memo1.lines.Count);
end;

// Code by francois.piette@overbyte.be  http://www.overbyte.be
function TForm2.EnumerateFunc(lpnr : PNETRESOURCE) : Boolean;
var
    dwResult     : DWORD;
    dwResultEnum : DWORD;
    hEnum        : THandle;
    cbBuffer     : DWORD;             // 16K is a good size
    cEntries     : DWORD;             // enumerate all possible entries
    lpnrLocal    : PNETRESOURCE;      // pointer to enumerated structures
    PtrResource  : PNetResource;
    i            : DWORD;
begin
    cbBuffer := 16384;
    cEntries := DWORD(-1);

    if Application.Terminated then begin
        Result := FALSE;
        Exit;
    end;

    dwResult := WNetOpenEnum(RESOURCE_GLOBALNET,
                             RESOURCETYPE_ANY,
                             RESOURCEUSAGE_CONTAINER, // enumerate allresources
                             lpnr,                    // NULL first timethis function is called
                             hEnum);                  // handle to resource

    if dwResult <> NO_ERROR then begin
        NetErrorHandler(dwResult, 'WNetOpenEnum');
        Result := FALSE;
        Exit;
    end;

    repeat
        // Allocate memory for NETRESOURCE structures.
        GetMem(lpnrLocal, cbBuffer);

        dwResultEnum := WNetEnumResource(hEnum,       // resource handle
                                         cEntries,    // defined locally as0xFFFFFFFF
                                         lpnrLocal,   // LPNETRESOURCE
                                         cbBuffer);   // buffer size

        if dwResultEnum = NO_ERROR then begin
            for i := 0 to cEntries - 1 do begin
                PtrResource := PNETRESOURCE(PChar(lpnrLocal) + i *SizeOf(lpnrLocal^));
                if PtrResource^.dwDisplayType = RESOURCEDISPLAYTYPE_SERVER then
                    DisplayStruct(PtrResource);
                Application.ProcessMessages;
                // If this NETRESOURCE is a container, call the function
                // recursively.
                if (RESOURCEUSAGE_CONTAINER = (PtrResource^.dwUsage and RESOURCEUSAGE_CONTAINER)) and
                   (PtrResource^.dwDisplayType <>RESOURCEDISPLAYTYPE_SERVER) then begin
                    if (not EnumerateFunc(PtrResource)) then begin
                        // TextOut(HandleDC, 10, 10, 'EnumerateFunc returned FALSE.', 29);
                    end;
                end;
            end;
        end
        else if dwResultEnum <> ERROR_NO_MORE_ITEMS then begin
            NetErrorHandler(dwResultEnum, 'WNetEnumResource');
            break;
        end;
    until dwResultEnum = ERROR_NO_MORE_ITEMS;

    FreeMem(lpnrLocal);

    dwResult := WNetCloseEnum(hEnum);

    if dwResult <> NO_ERROR then begin
        NetErrorHandler(dwResult, 'WNetCloseEnum');
        Result := FALSE;
        Exit;
    end;

    Result := TRUE;
end;

procedure TForm2.NetErrorHandler(
   dwResult  : DWORD;
   const Msg : String);
begin
    Application.MessageBox(PChar(Msg + ' Error #' + IntToStr(dwResult)),'Error', MB_OK);
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  EnumerateFunc(nil);
end;

end.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question