# Solved: Trying to clean up a batch file... need help



## raven6988 (Feb 4, 2010)

Hello,

I am currently working on doing a registry search for mulitple versions of a software using command line. I have the .bat file working but I am trying to find a way to clean it up so that, instead of showing error when a certain version is not found. It will only show the version that is showing up in the registry. Again this is all done thru remote connections and running scripts and I am trying to make it a bit more readable then dealing with 6 errors and then the information I want. Any help would be greatly appreciated. Below is the current .bat that I have working.

----
REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA8-7AD7-1033-7B44-A93000000001} /v DisplayName

REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA8-7AD7-1033-7B44-A92000000001} /v DisplayName

REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA8-7AD7-1033-7B44-A91000000001} /v DisplayName

REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA8-7AD7-1033-7B44-A80000000002} /v DisplayName

REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA8-7AD7-1033-7B44-A81000000002} /v DisplayName

REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA8-7AD7-1033-7B44-A81000000003} /v DisplayName"


As you can tell I am looking for the versions on a specific software load. But I have 20000 computers to do this on and instead of looking a all the errors in the script logs, I just want to see which value will actually show up. I have tried getting the FOR and IF statements but with no luck. Hopefully you all can help.


Raven


----------



## Squashman (Apr 4, 2003)

Redirect the output of the Reg Query to Nul and then check the error level of the previous command.


```
REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC7 6BA8-7AD7-1033-7B44-A93000000001} /v DisplayName >nul
If %errorlevel%==1 echo Registry key not found
```
Something like that. I am sure you can tweak it to your liking.


----------



## raven6988 (Feb 4, 2010)

Thank you for that. So far it looks like this 
@echo off
REG Query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{AC7 6BA8-7AD7-1033-7B44-A93000000001} /v DisplayName >nul
If %errorlevel%==0 echo "Program" version 9.3 is installed
If %errorlevel%==1 echo "Program" version 9.3 is not installed.


The only problem I am still having is that it is showing each error if the registry is not there to show the value.

"Error: The system was unable to find the specified registry key or value"

Is still being shown. It has been awhile since I did this level of scripting but is there a way to hide the error messages? If so what command am I looking for?

Thank you for the help thus far.

Raven


----------



## TheOutcaste (Aug 8, 2007)

Add *2>&1* after *>Nul*
make sure there is a space in front of the 2


----------



## raven6988 (Feb 4, 2010)

Thank you very much. That fixed my problem and was able to clean up my report significantly. I knew I was forgetting something but its been so long since I did scripting I am rusty.


----------



## Squashman (Apr 4, 2003)

TheOutcaste is like a hound dog. He sniffs out all my errors and cleans them up.


----------

