得到用户名:
var
Username : pChar;
nSize : Cardinal;
begin
Username:=StrAlloc(30);
nSize:=30;
GetUserName(Username,nSize);
ShowMessage(Username);
StrDispose(Username);
得到机器名:
function GetComputerName: AnsiString;
var lpBuffer: array[0..MAX_PATH] of char;
dwSize: DWORD;
begin
dwSize:= MAX_PATH;
if not Windows.GetComputerName(lpBuffer, dwSize) then
raise
Exception.Create(SysErrorMessage(GetLastError()));
Result:= StrPas(lpBuffer);
end;
var
Username : pChar;
nSize : Cardinal;
begin
Username:=StrAlloc(30);
nSize:=30;
GetUserName(Username,nSize);
ShowMessage(Username);
StrDispose(Username);
得到机器名:
function GetComputerName: AnsiString;
var lpBuffer: array[0..MAX_PATH] of char;
dwSize: DWORD;
begin
dwSize:= MAX_PATH;
if not Windows.GetComputerName(lpBuffer, dwSize) then
raise
Exception.Create(SysErrorMessage(GetLastError()));
Result:= StrPas(lpBuffer);
end;