Mega Code Archive

 
Categories / Delphi / Examples
 

Winusername

Getting user name and company info from Windows. Question: How do I retrieve the user name and company information from Windows? Answer: This information is stored under the "HKEY\CURRENT USER" section of the Windows registry. The task of retrieving this entry is greatly simplified by using the TRegIniFile component. Example: uses Registry; procedure TForm1.Button1Click(Sender: TObject); var reg: TRegIniFile; begin reg := TRegIniFile.create('SOFTWARE\MICROSOFT\MS SETUP (ACME)\'); Memo1.Lines.Add(reg.ReadString('USER INFO', 'DefName', 'Frank Borland')); Memo1.Lines.Add(reg.ReadString('USER INFO', 'DefCompany', 'A Valued Borland Customer')); reg.free; end; ***************************************** This probably useless (from elsewhere)... Here is a snippet of code in one of my apps: FUserName is declared in private portion of object. Modify to your liking. procedure TXXXObject.SetUserName; var dwUserNameLen : DWord; begin dwUserNameLen := dbiMaxUserNameLen + 1; //DBiTypes SetLength(FUserName, dwUserNameLen); if GetUserName(PChar(FUserName), dwUserNameLen) then //AdvApi32.Dll SetLength(FUserName, dwUserNameLen) else SetLength(FUserName, 0); end; -Sen > i believe that FUserName comes back as a zero terminated string and u can > recast it to > get the pascal string > getusername... > fUserName := String(Pchar(fUserName) )