Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to export the registry key HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe but am unable to do so, probably because of the percent signs.

I tried to escape the %-sign with a caret or another %-sign, but this didn't help me:

regedit /e c:\temp\cmd.reg "HKEY_CURRENT_USER\Console\%%SystemRoot%%_system32_cmd.exe"

and

regedit /e c:\temp\cmd.reg "HKEY_CURRENT_USER\Console\^%SystemRoot^%_system32_cmd.exe"

So, is there a way to do what I want.

Edit as per Ярослав Рахматуллин's comment: the key is the exact string, with the percent signs. So I don't want %SystemRoot% expanded, but passed to regedit as is.

share|improve this question
    
Do you want the variable to expand? As in do you want the key located at what would be the location in the tree if the proper value for the system root was inserted instead of variable? –  Ярослав Рахматуллин Oct 13 '12 at 8:13
    
No, the variable should not be expanded. –  René Nyffenegger Oct 13 '12 at 8:53

1 Answer 1

up vote 0 down vote accepted

1) Using a percent sign (%) in a batch file requires that two percent signs (%%) be specified.

This is working in batch files.

regedit /e c:\temp\123.reg "HKEY_CURRENT_USER\Console\%%SystemRoot%%_system32_cmd.exe"

2) This trick is working in "plain" command line of cmd.exe

set sr=SystemRoot
regedit /e c:\temp\123.reg "HKEY_CURRENT_USER\Console\%%sr%%_system32_cmd.exe"
share|improve this answer
    
It would be great to explain why this is working. A little context always helps! –  slhck Oct 13 '12 at 9:14
    
Sorry, it's more easy :) –  Maximus Oct 13 '12 at 9:56
    
It's interesting that this works in batch files. But I was actually after a way to run (or type) this in cmd.exe itself. And it doesn't work if not in a batch file. –  René Nyffenegger Oct 13 '12 at 10:18
    
Trick for command line –  Maximus Oct 13 '12 at 10:56
    
Do yourself a favor and install the PowerShell. CMD.exe is really not suitable, ...for anything. –  Ярослав Рахматуллин Oct 13 '12 at 11:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.