1. 程式人生 > >獲取計算機名稱

獲取計算機名稱

sock sas 計算機名稱 tco astar gethost finally soc gethostby

function GetComputerName:String; //獲取計算機名稱
//引用winsock
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;

獲取計算機名稱