參考﹕ procedure TForm1.Button5Click(Sender: TObject); Var Reg:TRegistry; begin Reg:=TRegistry.Create; Reg.RootKey:=HKEY_LOCAL_MACHINE; Reg.OpenKey('Software\Microsoft\Windows NT\CurrentVersion',False); Edit1.Text:='當前路徑:'+Reg.CurrentPath; Edit2.Text:='產品系列碼:'+Reg.ReadString('ProductId'); Edit3.Text:='產品名:'+Reg.ReadString('ProductName'); Edit4.Text:='註冊公司名:'+Reg.ReadString('RegisteredOrganization'); Edit5.Text:='用戶名:'+Reg.ReadString('RegisteredOwner'); Edit6.Text:='文件類型:'+Reg.ReadString('SoftwareType'); Reg.CloseKey; Reg.Free; end;
function TAPIMisc.myGetUserName : String; var pcUser : PChar; dwUSize : DWORD; begin dwUSize := 21; // user name can be up to 20 characters GetMem( pcUser, dwUSize ); // allocate memory for the string try if Windows.GetUserName( pcUser, dwUSize ) then Result := pcUser finally FreeMem( pcUser ); // now free the memory allocated for the string end; end;
procedure TForm1.Button5Click(Sender: TObject);
Var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
Reg.RootKey:=HKEY_LOCAL_MACHINE;
Reg.OpenKey('Software\Microsoft\Windows NT\CurrentVersion',False);
Edit1.Text:='當前路徑:'+Reg.CurrentPath;
Edit2.Text:='產品系列碼:'+Reg.ReadString('ProductId');
Edit3.Text:='產品名:'+Reg.ReadString('ProductName');
Edit4.Text:='註冊公司名:'+Reg.ReadString('RegisteredOrganization');
Edit5.Text:='用戶名:'+Reg.ReadString('RegisteredOwner');
Edit6.Text:='文件類型:'+Reg.ReadString('SoftwareType');
Reg.CloseKey;
Reg.Free;
end;
var
pcUser : PChar;
dwUSize : DWORD;
begin
dwUSize := 21; // user name can be up to 20 characters
GetMem( pcUser, dwUSize ); // allocate memory for the string
try
if Windows.GetUserName( pcUser, dwUSize ) then
Result := pcUser
finally
FreeMem( pcUser ); // now free the memory allocated for the string
end;
end;
大家知道,在winxp下用名分为名称,全名,描述三部份组成。所以,我得到只是用户名的名称这一部份。而实际上是想要名称和全名两部份。比如XP登陆时显示的就是用户名的全名。当然这些信息可以从注册表里得到。但是除些之外能不能用API函数直接得到,望大家不吝赐教。