function RegWriteExpandStringValue(const RootKey: Integer; const SubKeyName, ValueName, Data: String): Boolean;
Writes the specified REG_EXPAND_SZ-type registry value. Returns True if successful, False otherwise.
begin RegWriteStringValue(HKEY_CURRENT_USER, 'Software\My Company\My Program', 'UserName', '%UserName%); end;