Q&A

  • 분류먼저 해주시길 부탁드립니다.
안녕하십니까?

저는 WinNT를 사용하고 있는데....

현재 네트워크로 연결이 된 전체 도메인을 알수는 없나요....

그럼 즐거운 하루되세요...

1  COMMENTS
  • Profile
    김영대 2000.01.13 19:10
    은종범 wrote:

    > 안녕하십니까?

    > 저는 WinNT를 사용하고 있는데....

    > 현재 네트워크로 연결이 된 전체 도메인을 알수는 없나요....

    > 그럼 즐거운 하루되세요...



    unit Unit1;



    interface



    uses

    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

    StdCtrls, ComCtrls;



    type

    TForm1 = class(TForm)

    TreeView1: TTreeView;

    Button1: TButton;

    procedure Button1Click(Sender: TObject);

    procedure TreeView1Click(Sender: TObject);

    private

    { Private declarations }

    public

    { Public declarations }

    end;



    var

    Form1: TForm1;



    implementation

    {$R *.DFM}



    procedure GetServerList(TV:TTreeView; Node:TTreeNode);

    var

    a: Integer;

    ErrCode: Integer;

    NetRes: array[0..1023] of TNetResource;

    EnumHandle: THandle;

    EnumEntries: DWord;

    BufferSize: DWord;

    s: string;

    itm: TTreeNode;

    begin

    if not Node.HasChildren then

    try

    Screen.Cursor := crHourglass;

    with NetRes[0] do

    begin

    dwScope := RESOURCE_GLOBALNET;

    dwType := RESOURCETYPE_ANY;

    dwDisplayType := RESOURCEDISPLAYTYPE_generic;

    dwUsage := RESOURCEUSAGE_CONTAINER;

    lpLocalName := NIL;

    lpRemoteName := pChar(Tv.Selected.Text);

    lpComment := NIL;

    lpProvider := NIL;

    end;



    ErrCode := WNetOpenEnum(

    RESOURCE_GLOBALNET,

    RESOURCETYPE_ANY,

    RESOURCEUSAGE_CONTAINER,

    @NetRes[0],

    EnumHandle

    );

    if ErrCode = NO_ERROR then

    begin

    EnumEntries := 1023;

    BufferSize := SizeOf(NetRes);

    ErrCode := WNetEnumResource(

    EnumHandle,

    EnumEntries,

    @NetRes[0],

    BufferSize

    );

    if ErrCode = No_Error then

    with TV do

    try

    a:=0;

    Items.BeginUpdate;

    while a < enumEntries do

    with NetRes[a] do

    begin

    s:=lowercase(lpRemoteName);

    Delete(s,1,2);

    itm := Items.AddChild(node,s);

    itm.selectedIndex := 2;

    itm.imageindex := 2;

    inc(a);

    end;

    finally

    Node.expand(false);

    Items.EndUpdate;

    end;

    end;

    finally

    Screen.Cursor := crDefault;

    WNetCloseEnum(EnumHandle);

    end;

    end;



    procedure GetDomainList(TV: TTreeView);

    var

    a: Integer;

    ErrCode: Integer;

    NetRes: array[0..1023] of TNetResource;

    EnumHandle: THandle;

    EnumEntries: DWord;

    BufferSize: DWord;

    s: string;

    itm: TTreeNode;

    begin

    try

    with NetRes[0] do

    begin

    dwScope := RESOURCE_GLOBALNET;

    dwType := RESOURCETYPE_ANY;

    dwDisplayType := RESOURCEDISPLAYTYPE_DOMAIN;

    dwUsage := RESOURCEUSAGE_CONTAINER;

    lpLocalName := NIL;

    lpRemoteName := NIL;

    lpComment := NIL;

    lpProvider := NIL;

    end;



    ErrCode := WNetOpenEnum(

    RESOURCE_GLOBALNET,

    RESOURCETYPE_ANY,

    RESOURCEUSAGE_CONTAINER,

    @NetRes[0],

    EnumHandle

    );

    if ErrCode = NO_ERROR then

    begin

    EnumEntries := 1;

    BufferSize := SizeOf(NetRes);

    ErrCode := WNetEnumResource(

    EnumHandle,

    EnumEntries,

    @NetRes[0],

    BufferSize

    );

    WNetCloseEnum(EnumHandle);

    ErrCode := WNetOpenEnum(

    RESOURCE_GLOBALNET,

    RESOURCETYPE_ANY,

    RESOURCEUSAGE_CONTAINER,

    @NetRes[0],

    EnumHandle

    );

    EnumEntries := 1024;

    BufferSize := SizeOf(NetRes);

    ErrCode := WNetEnumResource(

    EnumHandle,

    EnumEntries,

    @NetRes[0],

    BufferSize

    );

    if ErrCode = No_Error then

    with TV do

    try

    a := 0;

    Items.BeginUpDate;

    Items.Clear;

    Itm := Items.Add(TV.Selected, string(NetRes[0].lpProvider));

    Itm.ImageIndex := 0;

    Itm.SelectedIndex := 0;



    while a < enumEntries do

    with NetRes[a] do

    begin

    s := lpRemoteName;

    Itm := Items.AddChild(Items[0], S);

    Itm.ImageIndex := 1;

    Itm.SelectedIndex := 1;

    inc(a);

    end;

    finally

    Items.EndUpdate;

    end;

    end;

    finally

    WNetCloseEnum(EnumHandle);

    end;

    end;



    procedure TForm1.Button1Click(Sender: TObject);

    begin

    GetDomainList(TreeView1);

    end;



    procedure TForm1.TreeView1Click(Sender: TObject);

    begin

    if TreeView1.Selected <> nil then

    if TreeView1.Selected.level = 1 then

    GetServerList(TreeView1, TreeView1.Selected);

    end;



    end.