function GetPCUserName: AnsiString; //得到用户名
var
lpName: PAnsiChar;
lpUserName: PAnsiChar;
lpnLength: DWORD;
begin
Result := '';
lpnLength := 0;
WNetGetUser(nil, nil, lpnLength); // 取得字串长度
if lpnLength > 0 then begin
GetMem(lpUserName, lpnLength+1);
if WNetGetUser(nil, lpUserName, lpnLength) = NO_ERROR then
Result := lpUserName;
FreeMem(lpUserName);
end;
end;
function GetUserNameEx: String;
var
sName: PChar;
iSize: DWORD;
begin
iSize := 255;
Result := '';
GetMem(sName,255);
try
if Windows.GetUserName(sName,iSize) then Result := sName;
finally
FreeMem(sName);
end;
end;