Q&A

  • 특정컴퓨터이름으로 연결여부 확인하기... 3시간쩨 찾다가... 지처서...
가지고 있는 소스는 있어여 그런데

컴파일 애러가 나서 해결이 않되어 다른 방법이 있는가 하구 찾아보다가

지처서 이렇게 질문을 올립니다.

부디 아시는 분은 조언 부탁드립니다....



참고로 제가 가지고있는 소스를 올려봅니다...



unit Unit1;



interface



uses

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

StdCtrls;



type

TForm1 = class(TForm)

Button1: TButton;

Edit1: TEdit;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;



var

Form1: TForm1;



implementation



{$R *.DFM}



function RemoteComputerExists(const ComputerName : String) : Boolean;



{ Returns True if the remote computer ComputerName exists on the network.

ComputerName must be of the form "Name". The function is not case-sensitive.

Be warned that this may take a *long* time to return.



Based on code supplied by:

Michael P. Bobowski

Atled Engineering Group

Milwaukee, WI }



function Enumerate(lpnr : PNetResource; const ComputerName : String): Boolean;

type

TNetResourceArray = array [0..16383] of TNetResource;

PNetResourceArray = ^TNetResourceArray;

var

hEnum: THandle;

BufferSize, Entry: Integer;

NumEntries: integer;

lpnrLocalc: PNetResourceArray;

begin

Result := False;



if NO_ERROR <> WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY,

0 {Usage: All resources}, lpnr, hEnum) then Exit;



BufferSize := 16384; {16 kB}

{Get as many entries as possible; NumEntries will be set to the number

actually read (if successfull)}

NumEntries := $FFFFFFFF;

lpnrLocalc := AllocMem(BufferSize);

repeat

case WNetEnumResource(hEnum, NumEntries, lpnrLocalc, BufferSize) of

NO_ERROR :

begin

for Entry := 0 to (NumEntries - 1) do

begin

{lpnrLocalc^[Entry].dwScope will be RESOURCE_GLOBALNET since that is

what we asked for}

if 0 = ANSICompareText(lpnrLocalc^[Entry].lpRemoteName,

ComputerName) then

begin

{lpnrLocalc^[Entry].dwDisplayType = RESOURCEDISPLAYTYPE_SERVER

should also be True}

{RESOURCEUSAGE_CONTAINER = (lpnrLocalc^[Entry].dwUsage and

RESOURCEUSAGE_CONTAINER) should also be True}

Result := True;

break;

end; {then}

{ResourceType is irrelevant}



if (lpnrLocalc^[Entry].dwDisplayType = RESOURCEDISPLAYTYPE_DOMAIN) or

(lpnrLocalc^[Entry].dwDisplayType = RESOURCEDISPLAYTYPE_NETWORK) then

begin

{Must recurse}

if RESOURCEUSAGE_CONTAINER = (lpnrLocalc^[Entry].dwUsage and

RESOURCEUSAGE_CONTAINER) then

begin

{Recursion possible}

Result := Enumerate(@(lpnrLocalc^[Entry]), ComputerName);

if Result then

break;

end; {then}

end; {then}

end; {for}

end; {NO_ERROR}



ERROR_MORE_DATA :

begin

{The buffer is too small for even one entry: increase the buffer...}

FreeMem(lpnrLocalc, BufferSize);

BufferSize := 2*BufferSize;

lpnrLocalc := AllocMem(BufferSize);

{...and try again}

end; {ERROR_MORE_DATA}



else

{

ERROR_NO_MORE_ITEMS (Enumeration is complete)

ERROR_INVALID_HANDLE (The handle given by the hEnum parameter is not valid)

ERROR_NO_NETWORK (No network is present)

ERROR_EXTENDED_ERROR (use WNetGetLastError for details)

}

break;

end; {case}

until Result;



FreeMem(lpnrLocalc, BufferSize);

WNetCloseEnum(hEnum);

end; {Enumerate}



begin

{Start enumeration at the root of the network}

Result := Enumerate(nil, ComputerName);

end;



procedure TForm1.Button1Click(Sender: TObject);

begin

if Pos('', Edit1.Text) = 0 then Edit1.Text := ''+Edit1.Text;



if RemoteComputerExists(Edit1.Text) then

ShowMessage('네트워크 컴퓨터가 존재합니다 ')

else ShowMessage('네트워크 컴퓨터가 존재하지 않습니다 ');

end;



end.



2  COMMENTS
  • Profile
    펑크 2000.08.05 22:16
    강민주님 팁중에서...



    uses

    shlobj;



    //리턴값은 선택한 컴퓨터 이름..

    function BrowseForComputer(const winhandle : THANDLE; const title : string) : string;

    //Pop up the standard 'Browse for computer' dialog box

    var

    BrowseInfo: TBrowseInfo;

    IDRoot: PItemIDList;

    Path: array[0..MAX_PATH] of Char;

    begin

    // Get the Item ID for Network Neighborhood

    SHGetSpecialFolderLocation(winHandle, CSIDL_NETWORK, IDRoot);

    ZeroMemory(@BrowseInfo, SizeOf(TBrowseInfo));

    ZeroMemory(@path, MAX_PATH);

    BrowseInfo.hwndOwner := winhandle;

    BrowseInfo.pidlRoot := IDRoot;

    BrowseInfo.lpszTitle := PChar(title);

    BrowseInfo.pszDisplayName := @path;

    // Include this flag to show computer only

    BrowseInfo.ulFlags := BIF_BROWSEFORCOMPUTER;// or BIF_RETURNONLYFSDIRS ;

    // Show the browse dialog, get the Item ID for the selected item and convert it to a path

    SHBrowseForFolder(BrowseInfo);

    // SHGetPathFromIDList(IDList, Path);

    result := path;

    end;





    procedure TForm1.Button1Click(Sender: TObject);

    begin

    Form1.Caption := BrowseForComputer(Handle, 'title...............???');

    end;





  • Profile
    김정식 2000.08.07 18:13
    답변에 감사합니다.

    그런제 제의도와 조금 다르네요.

    이것은 선택 창이 뜨는데....

    전 선택창이 아니라

    그컴이 접속되었는지

    여부를 알려주기만 하면 되지여....



    아뭏튼 감사드립니다..