// Author: ludao studio xotec Studio
// Component Library: xotecexpress.
In Delphi, functions are used to obtain the computer name, IP address, and Windows logon username of the local machine.
Uses Windows, Winsock;
{Computerlocalip}
// Obtain the IP address of the Local Machine
Function computerlocalip: string;
VaR
Ch: array [1 .. 32] of char;
Wsdata: twsadata;
Myhost: phostent;
I: integer;
Begin
Result: = '';
If wsastartup (2, wsdata) <> 0 Then exit; // can't start Winsock
Try
If gethostname (@ ch [1], 32) <> 0 Then exit; // gethostname failed
Except
Exit;
End;
Myhost: = gethostbyname (@ ch [1]); // gethostname Error
If myhost = nil then exit;
For I: = 1 to 4 do
Begin
Result: = Result + inttostr (ord (myhost. h_addr ^ [I-1]);
If I <4 then
Result: = Result + '.';
End;
End;
// Obtain the computer name of the Local Machine
{Computername}
Function computername: string;
VaR
Fstr: pchar;
Fsize: Cardinal;
Begin
Fsize: = 255;
Getmem (fstr, fsize );
Windows. getcomputername (fstr, fsize );
Result: = fstr;
Freemem (fstr );
End;
// Obtain the Windows logon User Name
{Winusername}
Function winusername: string;
VaR
Fstr: pchar;
Fsize: Cardinal;
Begin
Fsize: = 255;
Getmem (fstr, fsize );
GetUserName (fstr, fsize );
Result: = fstr;
Freemem (fstr );
End;