获取计算机名称

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;

posted @ 2018-02-04 09:41  快乐的正能量  阅读(159)  评论(0编辑  收藏  举报