在我程序中copy来的,能用,但别忘了在uses部分加 WinSock单元
function GetLocalUserName():string; //获得本机登录用户
var strUser
Char;
strSize
Word;
begin
strSize:=100;
struser:=StrAlloc(100); //¸østruserÉêÇëÄÚ´æ¿Õ¼ä
getusername(strUser,strSize);//µ÷Óú¯Êý
Result:=struser;
end;
function GetLocalIP():string; //本机IP
p: PHostEnt;
s : array[0..128] of char;
p2 : pchar;
WSAData:TWSAData;
begin
try
WSAstartup(2,WSAData);
{»ñµÃ¼ÆËã»úÃû}
GetHostName(@s, 128);
p := GetHostByName(@s);
{»ñµÃ±¾»úµÄipµØÖ·}
p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
result:=p2;
except
result:='';
end;
WSAcleanup;
end;
function GetLocalHostName():string;//本机主机名
var
s : array[0..128] of char;
WSAData:TWSAData;
i:integer;
strHostName:string;
begin
strHostName:='';
i:=0;
try
WSAstartup(2,WSAData);
{»ñµÃ¼ÆËã»úÃû}
GetHostName(@s, 128);
while s
<>chr(0) do
begin
strHostName:=strHostName+s;
i:=i+1;
end;
result:=strHostName;
except
result:='';
end;
WSAcleanup;
end;