1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Batch file issue - Program dettection

Discussion in 'DOS/Other' started by raven6988, Apr 20, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. raven6988

    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.
     
  2. TheOutcaste

    TheOutcaste

    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.
     
  3. raven6988

    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?
     
  4. TheOutcaste

    TheOutcaste

    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?
     
  5. raven6988

    raven6988 Thread Starter

    Joined:
    Feb 4, 2010
    Messages:
    28
    Yes I see it now. Thank you.
     
  6. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/918017

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice