![](https://images.cnblogs.com/cnblogs_com/xe2011/201207/201207260849553196.png)
{获取本机当前用户名}
//调用 返回值:= GetUser();
function GetUserName(): string;
var
Buffer: array[0..255] of Char;
Size: cardinal;
begin
Size := 256;
if GetUserName(Buffer, Size) then
begin
Result := Buffer
end
else
begin
Result := 'Unknown'
end;
end;
function GetUserName(): string;
var
Buffer: array[0..255] of Char;
Size: cardinal;
begin
Size := 256;
if GetUserName(Buffer, Size) then
begin
Result := Buffer
end
else
begin
Result := 'Unknown'
end;
end;
{获取计算机名}
//调用 返回值:= GetComputerName();
function GetComputerName(): string;
var
buffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
Size: Cardinal;
begin
Size := MAX_COMPUTERNAME_LENGTH + 1;
Windows.GetComputerName(@buffer, Size);
Result := StrPas(buffer);
end;
function GetComputerName(): string;
var
buffer: array[0..MAX_COMPUTERNAME_LENGTH + 1] of Char;
Size: Cardinal;
begin
Size := MAX_COMPUTERNAME_LENGTH + 1;
Windows.GetComputerName(@buffer, Size);
Result := StrPas(buffer);
end;