1

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:

Error

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?

1 Answer 1

2

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .