How-to hide error output from Reg Query command?
Posted: 27 May 2013 04:41
Hi fellow batches,
I am trying to hide the error output from the Reg Query command, if a registry entry do not exist.
Normally I would just add the command "nul 2>&1" to hide any output the command will give. But if I add this to the first line that generates the error message in case the registry do not exist, then none of the registry entries which was initially found, will be transfered to the output file "del.txt", which is the main purpose of the command.
I would very much like to have a clean batch file, so I hope someone can help me with a way to hide only the error output.
You can see my command underneath:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units" /f "Java Runtime Environment" /s | find "HKEY_LOCAL_MACHINE" > del.txt
for /f "tokens=* delims= " %%a in (del.txt) do reg delete "%%a" /f > nul 2>&1
Regards
Rubl
I am trying to hide the error output from the Reg Query command, if a registry entry do not exist.
Normally I would just add the command "nul 2>&1" to hide any output the command will give. But if I add this to the first line that generates the error message in case the registry do not exist, then none of the registry entries which was initially found, will be transfered to the output file "del.txt", which is the main purpose of the command.
I would very much like to have a clean batch file, so I hope someone can help me with a way to hide only the error output.
You can see my command underneath:
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Code Store Database\Distribution Units" /f "Java Runtime Environment" /s | find "HKEY_LOCAL_MACHINE" > del.txt
for /f "tokens=* delims= " %%a in (del.txt) do reg delete "%%a" /f > nul 2>&1
Regards
Rubl