如何用Delphi编程序取得Windows2000登录用户的用户名?
解决方案 »
- 主窗体的actiontoolbar如何动态添加子窗体的action
- 重学Delphi,请大家多多关照
- 连自已也无法相信的常规问题??????????????
- 监听访问我机器的用户
- 请问如何屏蔽form窗口的关闭按钮
- Delphi6.0的Update pack 2哪里有下载,找了好几个地方,都没办法下载
- 请教各位高手,大家不要笑话我!在三层结构里面怎么开始一个事务,我是新手,谢谢了!
- 请问怎样才能让TreeView的树图标放大?
- 如何定义TSocketNotifyEvent的过程?
- 求救,Image控件中的图像怎么才能复制到剪贴板中
- Dephi中什么数据库控件操作数据库最快呢?
- 看了cg1120 这位幸福仁兄的贴很让我感动
function GetCurrentUserName : string;
const
cnMaxUserNameLen = 254;
var
sUserName : string; dwUserNameLen : DWord;
begin
dwUserNameLen := cnMaxUserNameLen-1;
SetLength( sUserName, cnMaxUserNameLen );
GetUserName( PChar( sUserName ), dwUserNameLen ); SetLength( sUserName, dwUserNameLen );
Result := sUserName;
end;或:
//================================================================
// Function: GetMachine()
// 获取本机器的名称
// 参数:无
// 返回:string
// 完成度:95%
//================================================================ function GetMachine: string;
var
n: dword;
buf: pchar;
const
rkMachine = {HKEY_LOCAL_MACHINE}
'\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName';
rvMachine = 'ComputerName';
begin
n := 255;
buf := stralloc(n);
GetComputerName(buf, n);
result := buf;
strdispose(buf);
with TRegistry.Create do
begin
rootkey := HKEY_LOCAL_MACHINE;
if OpenKeyReadOnly(rkMachine) then
begin
if ValueExists(rvMachine) then
result := ReadString(rvMachine);
closekey;
end;
free;
end;
end; //================================================================
// Function: GetUser()
// 获取系统中,当前用户的用户名
// 参数:无
// 返回:string
// 完成度:95%
//================================================================ function GetUser: string;
var
n: dword;
buf: pchar;
begin
n := 255;
buf := stralloc(n);
GetUserName(buf, n);
result := buf;
strdispose(buf);
end;