Reg query to display silent

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Adrianvdh
Posts: 177
Joined: 16 May 2013 13:00

Reg query to display silent

#1 Post by Adrianvdh » 03 Jul 2013 04:08

Hello everyone...

I am playing around with reg, and reg query a lot, but I want to check if a key exist with out it showing "ERROR:"

This is what I have so far to that...

Code: Select all

reg query "%RegKey%" /e >nul>nul
if "%errorlevel%"=="1" >nul reg add "%RegKey%" /ve


So if you don't know how that code will work I will explain... The first line is the read the reg key, mmmK. The second one uses "errorlevel" that is if it returns true or false, but if it returns false it will make the key because it does not exist but gives me an error, which I would like to hide

But my ">nul>nul" wont work any suggestions

Thanks for your time :)

penpen
Expert
Posts: 1992
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Reg query to display silent

#2 Post by penpen » 03 Jul 2013 04:55

Using >nul twice is not useful, as it does the same as one >nul:
It writes the output of the standard output to the nul device.

Your problem is, that the output of the standard error stream (STDERR) is still written to the console window.
You can avoid this by redirecting STDERR (with handle 2) to the nul device, too:

Code: Select all

reg query "%RegKey%" /e >nul 2>nul


penpen

Post Reply