I need to use a REG QUERY command to view the value of a key and set the result into a variable with this command:
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "KeyName" /v ValueName') DO SET Variable=%%B
But if the key doesnt exists i get an error shown in the console. I need to hide this error! I tried putting a 2>nul after the command to stop the stderr, but this works if i only call the command:
REG QUERY "KeyName" /v ValueName 2>nul
If i put it into the FOR command like this:
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "KeyName" /v ValueName') DO SET Variable=%%B 2>nul
The error is shown. So does anyone know how to hide the error? Or maybe another command too see if a key exists or not?
Thanks
PS: I'm using Windows XP