Solved: Batch file issue - Program dettection

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

raven6988

Thread Starter
Joined
Feb 4, 2010
Messages
28
Hello again,

I am having an issue with a .bat that I have written. All it does is tell me which version of a program is installed. But I am trying to remember how to write the FOR statement so that if the program is not installed it show a message and not the error stating the registry entry does not exist. It is a simple FOR statement but I am having issues writing the Else portion of it. All I get with the FOR statements I write with the else do not even work...

Please help.

Below is the Working For statement.

FOR /F "tokens=2* delims= " %%A IN ('REG Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SnagIt7" /v DisplayVersion') DO Set _Snaginf=%%B
echo . = SnagIt Version %_Snaginf% is installed.


Please help.

Thanks again.
 
Joined
Aug 7, 2007
Messages
9,028
Code:
Set _Snaginf=
FOR /F "tokens=2* delims= " %%A IN ('REG Query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SnagIt7" /v DisplayVersion 2^>Nul') DO Set _Snaginf=%%B
If "%_Snaginf%"=="" (Echo.Snagit is not installed) Else echo.SnagIt Version %_Snaginf% is installed.
The 2^>Nul will keep the ERROR: The system was unable to find the specified registry key or value. message from being displayed.
 

raven6988

Thread Starter
Joined
Feb 4, 2010
Messages
28
Thank you That really helps. How can I show an echoed message if a program is not found?
 
Joined
Aug 7, 2007
Messages
9,028
If the Snagit registry key is not found it displays Snagit is not installed. That's the Echo statement on the left side of the Else clause. Isn't that what you wanted?
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top