2

In CMD Console (Interactive Mode), I run the command:

reg query HKCU\Console\%%Startup

The output:

HKEY_CURRENT_USER\Console\%%Startup
    DelegationConsole    REG_SZ    {B23D10C0-E52E-411E-9D5B-C09FDF709C7D}
    DelegationTerminal    REG_SZ    {B23D10C0-E52E-411E-9D5B-C09FDF709C7D}

When I save the command to a bat file:

@reg query "HKCU\Console\%%Startup"& pause 

I get an error:
ERROR: The system was unable to find the specified registry key or value.

Is there a different writing format between CMD and bat files?
What is wrong?
Thanks.

2
  • 2
    Yes, the % needs to be escaped. I believe to escape a %, you write %%, so in your case, %%%%
    – LPChip
    Commented May 25 at 11:25
  • @LPChip Thank You. I just discovered this trick. Make this comment as an answer, maybe it will be useful for others in the future.
    – Mr.Key7
    Commented May 25 at 11:35

1 Answer 1

2

When working in a batchscript, the % sign has a meaning. They can be used with variables, for example %test% but also %1 etc.

When you use for normally (in cmd), you do for %i ... But for /? will also mention this, you have to use for %%i in a batch script. You are basically escaping the % by writing %%.

enter image description here

So to answer your question, you would need to escape both % % by writing %% %%, as such:

@reg query "HKCU\Console\%%%%Startup"& pause
0

You must log in to answer this question.

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