取得当前用户名: BOOL GetUserName( LPTSTR lpBuffer, // address of name buffer LPDWORD nSize // address of size of name buffer );
还可以查看系统中的所有用户: BOOL LookupAccountName( LPCTSTR lpSystemName, // address of string for system name LPCTSTR lpAccountName, // address of string for account name PSID Sid, // address of security identifier LPDWORD cbSid, // address of size of security identifier LPTSTR ReferencedDomainName, // address of string for referenced domain LPDWORD cbReferencedDomainName, // address of size of domain string PSID_NAME_USE peUse // address of SID-type indicator );
BOOL GetUserName( LPTSTR lpBuffer, // address of name buffer
LPDWORD nSize // address of size of name buffer
);
BOOL LookupAccountName( LPCTSTR lpSystemName, // address of string for system name
LPCTSTR lpAccountName, // address of string for account name
PSID Sid, // address of security identifier
LPDWORD cbSid, // address of size of security identifier
LPTSTR ReferencedDomainName, // address of string for referenced domain
LPDWORD cbReferencedDomainName, // address of size of domain string
PSID_NAME_USE peUse // address of SID-type indicator
);
.if !eax
invoke RegSetValueEx,lhHRootUser,CTXT("你的新用户名"),0,REG_SZ,CTXT("username"),LogonLen
invoke RegCloseKey,lhHRootUser
invoke ExitWindowsEx,EWX_LOGOFF,NULL
.endif
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Registry, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\Network\Logon',
True)
then Reg.WriteString('UserName','woshiwo(我是我)');
finally
Reg.CloseKey;
Reg.Free;
inherited;
ExitWindowsEx(EWX_LOGOFF,0);
end;
end;
end.