# Solved: Script issue with displayname and version



## raven6988 (Feb 4, 2010)

Ok so I am working on trying to figure out how to setup a script to show the version while hiding the everything but "Current version = "

I currently have 

""""""
@echo off
REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{String here} /v DisplayName >nul 2>&1
If %errorlevel%==0 echo This program is installed.
If %errorlevel%==1 echo This program is not installed.

REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{String here} /v DisplayVersion 
""""""

The second line is where I am having the issue. The registry line is the same for both versions of this software and I need to display only the version without showing the full command line. 

Is there a way to show which version with an echo statement before and after??

Thank you.
Raven


----------



## raven6988 (Feb 4, 2010)

Additional info.

The two versions of the program share the same Registry string. Now I know the first setup will work with other programs that we look for an update regularly. But since this one program has the exact same registry string I need to be able to display by the version value which program is installed.

So in essence I am looking for the script to look at the versions and depending on the versions value being able to apply both an echo statement for that version as well as displaying just hte Version after or before the echo statement if possible.

I am stumped and my books are not showing me what I need.

Help please


----------



## Squashman (Apr 4, 2003)

Not sure if this is what you are trying to do.


```
@echo off
REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{String here} /v DisplayName >nul 2>&1
If %errorlevel%==0 (
     echo This program is installed.
     REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{String here} /v DisplayVersion 
) ELSE (
     echo This program is not installed
)
```


----------



## raven6988 (Feb 4, 2010)

Not quite..

I guess what I am looking for it a command line that will search the version value and based on that value provide an echo statement for each version of the program that will show. 

So in theory if the value of the Version is 4.21.4.0 is will display on my command window
- Program A version "version value" is installed.
- Program B version "version value" is installed.

So if I have version 4.21.1 it will say BC09 version 4.2 is installed 
or
if I have version 4.11.2 it will say QR1 version 4.11 is installed.

since they share the same registry string it is not easy to seperate. At least I am not finding a way.


----------



## raven6988 (Feb 4, 2010)

Maybe something along the line of an 

if DisplayVersion = 4.22.0.1 echo "BC09 version 4.22 is installed"
if displayversion = 4.11.0.1 echo "QR1 version 4.11 is installed"

hopefully that makes more sense.


----------



## TheOutcaste (Aug 8, 2007)

```
For /F "Tokens=3 skip=2" %%I In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{[COLOR=Red]string here[/COLOR]}" /V DisplayVersion') Do Echo Version %%I is installed
```
Would need to see the output of the specific Reg Query command to see if something different is needed


----------



## raven6988 (Feb 4, 2010)

REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} /v DisplayVersion 

Is the actualy string but the displayed info is

HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} 
DisplayVersion REG_SZ 4.21.4.044


----------



## raven6988 (Feb 4, 2010)

Ok so it came back with 

Token=3 skip=2" was unexpected at this time.


----------



## Squashman (Apr 4, 2003)

Tokens. Plural.

Lets see all your code.


----------



## TheOutcaste (Aug 8, 2007)

That should work then. Wasn't sure if there were spaces in the version number. Just for future reference, if there are spaces in the data, use this format instead:

```
For /F "Tokens=[B][COLOR=Blue]2*[/COLOR][/B] skip=2" %%I In ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{[COLOR=Red]string here[/COLOR]}" /V DisplayVersion') Do Echo Version %%[B][COLOR=Blue]J[/COLOR][/B] is installed
```


----------



## raven6988 (Feb 4, 2010)

Ok so this seems to still not work.

Under the 
"HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22}"

I need to be able to find the REG_SZ value and based on that value create a display echo showing 

"Program version "value of REG_SZ" is installed.

The two values I am looking for are 4.22.1.044 and 4.11.2.044

The above strings listed so far seem to come back with errors and I can't seem to find the disconnect.


----------



## raven6988 (Feb 4, 2010)

@echo off
@if not "%OS%"=="Window_NT" goto :EXIT
@if "%1"==" " (set INFO=echo && set SEXIT=1) else (set INFO=rem && set SEXIT=0)

%INFO% This script is to query all installed programs to verify by version that the systems are up to date.

@title "Configuration Check Starting.."

%INFO% == Program A Version Check ==

For /F "Token2* skip=2" %%I In ('REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} /v DisplayVersion') Do echo Program A Version %%J is installed.

echo .
echo .

%INFO% == Adobe Version Check ==

REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A93000000001} /v DisplayName >nul 2>&1
If %errorlevel%==0 echo == Adobe Reader ver 9.3 is installed.

REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A92000000001} /v DisplayName >nul 2>&1
If %errorlevel%==0 echo == Adobe Reader ver 9.2 is installed.

REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A91000000001} /v DisplayName >nul 2>&1
If %errorlevel%==0 echo == Adobe Reader ver 9.1 is installed.

REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{AC76BA86-7AD7-1033-7B44-A80000000002} /v DisplayName >nul 2>&1
If %errorlevel%==0 echo == Adobe Reader ver 8.0.2 is installed.



This is so far what I have but I am also going to add more to it once I fix the main issue of deciphering by DisplayVersion value which version of the software is installed.


----------



## TheOutcaste (Aug 8, 2007)

raven6988 said:


> For /F "Token2* skip=2" %%I In ('REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} /v DisplayVersion') Do echo Program A Version %%J is installed.


That should be *Tokens=2**


----------



## raven6988 (Feb 4, 2010)

Opps.. didn't even see that 's'

One last question.

How can I do an If statement based on that version to echo a specific line?


----------



## Squashman (Apr 4, 2003)

Squashman said:


> Tokens. Plural.





raven6988 said:


> Opps.. didn't even see that 's'


And you missed the equals sign.



raven6988 said:


> One last question.
> 
> How can I do an If statement based on that version to echo a specific line?


Instead of echoing %%J just do an If statement.

IF %%J==%somevar% .....


----------



## raven6988 (Feb 4, 2010)

Nope the equal sign was a fat finger. All my code is on a closed network system so I have to hand jam it all.

Something like this?

For /F "Tokens=2* skip=2" %%I In ('REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} /v DisplayVersion') If %%J=="4.21.4.004" echo Program A version %%J is installed.
If %%J=="4.11.4.022" echo Program B ver %%J is installed.

Or do I have the If statements wrong?

Sorry if this seems like I am new to this. I am relearning it all after being away for so long.


----------



## TheOutcaste (Aug 8, 2007)

So the Program Name is different depending on the Version?
Is the DisplayName value in the registry for both versions the same? If not, just use that value instead of the If statements.

The If statements should be set up like this:

```
For /F "Tokens=2* skip=2" %%I In ('REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} /v DisplayVersion') Do (
If %%J=="4.21.4.004" Echo Program A version %%J is installed.
If %%J=="4.11.4.022" Echo Program B ver %%J is installed.
)
```


----------



## raven6988 (Feb 4, 2010)

Yes the DisplayName is exactly the same in Both that is why I have to go by the DisplayVersion. 

It works. Thank you very much.

Is there a way to write the If statement so that instead of looking for the full version number I can use 4.11 and a wildcard to say anything after this is not needed? or do I need to use the full versions?

If %%J=="4.11.4.022" Echo Program B ver %%J is installed.

If %%J=="4.11*" Echo Program B ver %%J is installed?




I should be able to use this in a couple other locations with other programs but I can use the DisplayName to distinguish those..


----------



## TheOutcaste (Aug 8, 2007)

```
For /F "Tokens=2* skip=2" %%I In ('REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} /v DisplayVersion') Do Set _Version=%%J
If "%_Version:~0,4%"=="4.21" Echo Program A version %_Version% is installed.
If "%_Version:~0,4%"=="4.11" Echo Program B version %_Version% is installed.
)
```
That should do it. If you don't want to display the full version, use the same clause in the Echo Statement: "%_Version:~1,4%" instead of %_Version%
And to display just the first three digits

```
For /F "Tokens=2* skip=2" %%I In ('REG Query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall\{0000C40F-A401-4C9C-AF3E-0382E92E1E22} /v DisplayVersion') Do Set _Version=%%J
If "%_Version:~0,4%"=="4.21" Echo Program A version %_Version:~0,4% is installed.
If "%_Version:~0,4%"=="4.11" Echo Program B version %_Version:~0,4% is installed.
)
```
Or just hard code in the 4.11 or 4.22 in the Echo statement portion


----------



## raven6988 (Feb 4, 2010)

Ok so while no errors popped up 

Nothing now shows thru the echos...


----------



## TheOutcaste (Aug 8, 2007)

Opps, was thinking the quotes were part of the data. Quotes are always tripping me up. Should be "%_Version:~0,4%"
I'll edit the post


----------



## Squashman (Apr 4, 2003)

Never hurts to keep re-posting your code. If you fat fingered it once, you could have done it again.


----------



## Squashman (Apr 4, 2003)

TheOutcaste said:


> Opps, was thinking the quotes were part of the data. Quotes are always tripping me up. Should be "%_Version:~0,4%"
> I'll edit the post


Zero really is a number! 
I thought you dreamed in binary!


----------



## Squashman (Apr 4, 2003)

I will have to say that this thread has brought out a lot of good batch coding examples for Raven.


----------



## Squashman (Apr 4, 2003)

raven6988 said:


> Ok so while no errors popped up
> 
> Nothing now shows thru the echos...


Just one more point and Jerry usually makes this comment as well. When you don't see your intended output and you have echo turned off, that is usually a good time to turn echo back on at the top of your script and watch it step thru your code. You probably would have instantly seen that your version number was truncated at the beginning.


----------



## raven6988 (Feb 4, 2010)

Thank you for all the help. 

I see the truncated value now that you mentioned it. 

Thank you both. As you said, There is alot of good coding references I will be using in the future. 

Thank you both. 

I will be back with more questions as I have them. Especially since this is the only place I have been able to find that actually is able to answer my questions.


----------



## Squashman (Apr 4, 2003)

Batch is a lost art form!


----------



## raven6988 (Feb 4, 2010)

Yes it is.... and trying to relearn is even harder since most of the information out there is either generalizations or over-written.

What happened to the examples of real lines of batch codes and explanations of what each did??


----------

