delphi 获取计算机名和用户名


本文整理自网络,侵删。

 
function CurrentUserName: String;
var
  nSize: DWord;
begin
  nSize := 1024;
  SetLength(Result, nSize);
  if GetUserName(PChar(Result), nSize) then
    SetLength(Result, nSize - 1)
  else
    RaiseLastOSError;
end;

function CurrentDomain: String;
const
  DNLEN = 255;
var
  sid: PSID;
  sidSize: DWord;
  sidNameUse: DWord;
  domainNameSize: DWord;
  domainName: array [0 .. DNLEN] of Char;
begin
  Result := '';

  sidSize := 65536;
  GetMem(sid, sidSize);
  domainNameSize := DNLEN + 1;
  sidNameUse := SidTypeUser;
  try
    if LookupAccountName(nil, PChar(CurrentUserName), sid, sidSize, domainName,
      domainNameSize, sidNameUse) then
      Result := strpas(domainName);
  finally
    FreeMem(sid);
  end;
end;

 EdtUsername.Text := CurrentUserName();
  EdtDomain.Text := CurrentDomain();

相关阅读 >>

Delphi like 通配符的使用

Delphi处理http请求自定义header

Delphi从内存(memorystream)使用wmp

Delphi 将图片压缩后转base64函数

Delphi 中文字符串截取

Delphi 一个线程安全的轻量级的日志类

Delphi 记录鼠标点击坐标

Delphi中最小化其他程序及所有程序窗口最小化

Delphi rest 服务器返回utf16编码转换成正常string

Delphi区分汉字和字母的函数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...