如何用Delphi编程序取得Windows2000登录用户的用户名? 如何用Delphi编程序取得Windows2000登录用户的用户名? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试以下函数: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; delphi怎样连接Sqlite 增删改查 超级郁闷的问题 装了DELPHI2007的进来。100分相送 小问题,大侠帮忙! dbedit使用时候的问题 新手在看例子时遇到不明白,请各位指教 有好看的XP控件吗,在哪可以下载?像金山毒霸那样的 opendialog为什么不能使用向上按钮? 大家这么使用过COM吗?原来COM可以这么使用的! 一个基于IOCP服务器 发送的问题 如何通过拨号获得目标机器的IP地址? 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;