如何查找网络中的某一台计算机,并获得名称?

解决方案 »

  1.   

    function GetComputerName:string;
    var
       wVersionRequested : WORD;
       wsaData : TWSAData;
       p : PHostEnt; s : array[0..128] of char;
    begin
       try
          wVersionRequested := MAKEWORD(1, 1); //创建 WinSock
          WSAStartup(wVersionRequested, wsaData); //创建 WinSock
          GetHostName(@s,128);
          p:=GetHostByName(@s);
          Result:=p^.h_Name;
       finally
          WSACleanup; //释放 WinSock
       end;
    end;