I have a logon script that imports a registry key. No big deal. This works.

My wish is to have the registry populate the current user logged on into that field.

So presently I have to manually edit the .reg file and input "domain\user" for each user in our department.

Is there a way to substitute "domain\user" for "%username%" that way the registry key is imported by User D and the registry key populates "domain\UserD" ?

Thank you for your input. Using Windows 7.

  • Perhaps using Group Policy Preferences rather than a logon script would be a better solution. – joeqwerty Feb 9 '18 at 14:37
  • Why you don't populate the HCU subset ? – yagmoth555 Feb 9 '18 at 14:38
  • For each user I have to go in the .reg file and input the "domain\user" for them. Essentially I would have to create one .reg file for each user. I'm trying to use just one .reg file and apply to all users. If anyone can help me figure out how to do that then I would be able to push it via GPO. – Victor Antifries Feb 9 '18 at 14:45

You can only use environmental values in REG_EXPAND_SZ


Simliar question is on Super User.


  • Thanks for the information Rick. Is there a way to create a script that scans my .reg file and does a find and replace function ? I'm thinking I would say .....find "domain\user" replace with domain\%username% then save .reg. – Victor Antifries Feb 9 '18 at 14:54
  • either use a REG_EXPAND_SZ key or write a vbs logon script that does a find and replace :) newString = Replace(oldString, "domain\user" , userName) – RickWeb Feb 9 '18 at 15:05
  • userName = objShell.ExpandEnvironmentStrings("%username%") newString = Replace(oldString, "domain\user" , userName) – RickWeb Feb 9 '18 at 15:11
  • Awesome. Thank you very much. I'll go work on that. I really appreciate your input. – Victor Antifries Feb 9 '18 at 15:20
  • No problem just search for vbs logon script or vb script there are loads of examples and help. – RickWeb Feb 9 '18 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.