本文整理自网络,侵删。
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 程序运行提示 “database login”对话框,让输入adoconnection1 的username和password
Delphi string.create(char,count)
更多相关阅读请进入《Delphi》频道 >>