0

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 09 '18 at 14:37
  • Why you don't populate the HCU subset ? – yagmoth555 Feb 09 '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 09 '18 at 14:45

1 Answers1

0

You can only use environmental values in REG_EXPAND_SZ

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724884(v=vs.85).aspx

Simliar question is on Super User.

https://superuser.com/questions/1158516/usage-of-username-in-registry

RickWeb
  • 285
  • 2
  • 13
  • 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 09 '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 09 '18 at 15:05
  • userName = objShell.ExpandEnvironmentStrings("%username%") newString = Replace(oldString, "domain\user" , userName) – RickWeb Feb 09 '18 at 15:11
  • Awesome. Thank you very much. I'll go work on that. I really appreciate your input. – Victor Antifries Feb 09 '18 at 15:20
  • No problem just search for vbs logon script or vb script there are loads of examples and help. – RickWeb Feb 09 '18 at 15:24