2

Consider the following key, as an example

HKEY_CLASSES_ROOT\txtfile\shell\open\command

and its (Default) value

%SystemRoot%\system32\NOTEPAD.EXE %1

This value determines what will happen when you double click on a .txt file. %SystemRoot% and %1 are variables that can be interpreted by cmd.exe. An equivalent command in PowerShell would look like

$env:SystemRoot\system32\NOTEPAD.EXE $args[0]

However if you set the registry value to the Powershell equivalent it will only create an error, because it is cmd.exe trying to interpret it, and not PowerShell. Can Windows be set in such a way to allow PowerShell to be the interpreter instead of cmd.exe?

3

No you cannot set Windows to use PowerShell style variables in the registry. Doing so would be a breaking change for many applications since cmd.exe is not the only one that can expand environment variables.

For example, you can expand environment variables using .NET with:

[Environment]::ExpandEnvironmentVariables('%SystemRoot%\system32\NOTEPAD.EXE %1')

You can also enter %HOME% in the run dialong (Win+R) or in the Windows Explorer address bar to open your home directory. Neither of these use cmd.exe to expand the variables.

3rd party applications can also parse the strings themselves, and look up the values in the registry. Because of Microsoft's concern for backwards compatibility, I doubt Windows would change the way environment variables are stored in the registry.

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.