I'm deploying VSCode with baseline settings to shared high-school computer labs. During installation, I create an Active Setup entry whose StubPath creates an HKCU RunOnce value. That RunOnce command should launch a short PowerShell script, which copies a preset settings.json from a hidden folder on C: to the current user's AppData directory.
The command works when the script path has no spaces, for example:
REG ADD HKCUSoftwareMicrosoftWindowsCurrentVersionRunOnce /v VSCodeCopy /t REG_SZ /d "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -ExecutionPolicy Bypass -File C:MyPathVSCode_CopySettings.ps1"
However, it fails when the script is located at C:My PathVSCode_CopySettings.ps1. I have tried single quotes, double quotes, and several escaping combinations. RunOnce appears to launch PowerShell, but the window immediately closes. Even adding Read-Host inside both the try and catch blocks does not pause the window.
The HKCU RunOnce value is created by the Active Setup StubPath rather than directly by the installer, so the command passes through cmd.exe and has additional quoting and length limitations. I am using this combination so the configuration runs once for both existing and new users, with a future Active Setup Version value available if the settings need to be refreshed.
What is the correct way to quote the script path, and is there a better approach for this setup?
3 Answers
This is a case where avoiding the extra command layers would make things much simpler. A PowerShell command such as Set-ItemProperty or New-ItemProperty can create the RunOnce value directly, with the script path stored as a properly quoted string. If Active Setup is mandatory, keep the StubPath as short as possible and have it call a small helper script rather than embedding a long nested PowerShell command.
Consider using a scheduled task with a user-logon trigger instead of chaining Active Setup and RunOnce. Task Scheduler gives you clearer control over the user context, whether the task runs once or repeatedly, hidden execution, logging, and error handling. Active Setup can work, but the combination of registry parsing, cmd.exe quoting, PowerShell argument parsing, and RunOnce makes troubleshooting unnecessarily difficult.
The path itself needs double quotes; single quotes are not reliable here because the command is ultimately being parsed by cmd.exe. The RunOnce data should look like this:
powershell.exe -ExecutionPolicy Bypass -File "C:My PathVSCode_CopySettings.ps1"
When creating the value with REG ADD, make sure those inner double quotes survive the outer quoting used for /d. Also, you probably do not need the fully qualified path to powershell.exe since it is normally available through PATH. The issue is not the 260-character limit or the space by itself, but how the command is being quoted as it passes through Active Setup, cmd.exe, and RunOnce.

The command works when entered directly in cmd or PowerShell, but Active Setup adds another parsing layer because its StubPath launches cmd.exe. Using PowerShell to create the RunOnce value also makes the nested command too long for this arrangement, so the quoting has to work within the registry string itself.