reg
is a Command Prompt command. When you call
reg add
you are supposed to call it from cmd. Therefore, the easiest solution for you is to put your code to a file with and extension of .bat or .cmd. Create an empty file with .bat or .cmd extension and copy and paste
your command there:
reg add HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo /v username /t reg_sz /d %username% /f
BTW, if you really want to use a registry editor script (files with an extension of .reg) then change the file format like this:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo]
"username"="xxxxxxxx"
By using this option you will not be able to pass Environment Variables. You will have to prepare the file content to populate the value in the .reg file