function GetComputerName:string;
var computername
Char;
len
Word;
begin //获取计算机名
len:=30;
getmem(computername,30);
windows.GetComputerName(computername,len);
Result:=computername;
end;
function GetMyHostName:string;
const
bufsize=255;
var
buf: pointer;
RemoteHost : PHostEnt; (* No, don't free it! *)
begin //获取本机主机名
buf:=NIL;
Result:='';
try
getmem(buf,bufsize);
winsock.gethostname(buf,bufsize); (* this one maybe without domain *)
if char(buf^)<>#0 then begin
RemoteHost:=Winsock.GetHostByName(buf);
if RemoteHost<>NIL then
(*$ifdef ver80 *)
Result:=strpas(pchar(RemoteHost^.h_name))
(*$else *)
Result:=pchar(RemoteHost^.h_name)
(*$endif *)
else Result:='127.0.0.1'; (* no Hostname received *)
end
else Result:='127.0.0.1'; (* no Hostname received *)
finally
if buf<>Nil then freemem(buf,bufsize);
end;
end;