I have a software application that I must deploy to the enterprise, and part of it relies on having the script run as the user's context. So my deployment script loops through all the HKU SIDs and adds to HKU{sid}\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce a value.

Name: Stage Macro Connections
Value: wscript.exe "C:\Users\{username}\appdata\local\SmartViewConnections\StagedMacro.vbs"

Part of this process also includes adding that to the default user profile, so I mount C:\Users\Default\ntuser.dat and add a similar value:

Name: Stage Macro Connections
Value: wscript.exe "%localappdata%\SmartViewConnections\StagedMacro.vbs"

I then unmount it and carry on my merry way. I use the default profile so that people who have never logged into any given PC can still take advantage of the automation accomplished with the StagedMacro.vbs.

The problem happens when a new user logs on to the computer. The RunOnce keys get executed, but I receive the following error message:


Short of targeting a batch script that dynamically pulls the username and acts as a wrapper to point to the VBS script, can anybody explain this behavior and potentially how to overcome it?


To use an environment variable such as %localappdata% in a registry value, and have it be populated (expanded/replaced) later with the contents of the environment variable, you'll need to write the value to the registry as type "Expandable String Value" instead of "String Value". Upon write, the environment variable will be in the registry as expected. Later, when the profile is loaded and Windows performs a read operation, it should expand the environment variable automatically.

  • 1
    Thanks for that explanation. I'll have to do some testing to verify this on my own, but I do appreciate it. – Joshua Parnell Feb 24 at 21:48
  • Awesome. Let me know if you have any more trouble. – Frank Lesniak Feb 26 at 4:55

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.