Errorlevel in Script not Functioning

Posted on 2011-05-11
Last Modified: 2012-05-11
I am trying to run the following batch script and it is not doing what I want it to. I want it to check to see if the version of a program exists in the registry and if it does, then uninstall it and install a later version but if it does not exists in the registry then just quit. The problem I am having is that it installs no matter if the version exists in the registry or not. I then want to creae a computer configuration start up script to push this out. Here is the code:
@echo off

REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\FFD0D1F8C889BA64A87750A079B96B05\InstallProperties /v DisplayVersion | Find "DisplayVersion      REG_SZ  7.5.087"

If ErrorLevel 0 goto Exists
If ErrorLevel 1 goto Not_Exists


msiexec.exe /m /x "\\myserver\old.msi" /qn

msiexec.exe /i "\\myserver\new.msi" /qn /norestart


Echo EC 7.5.087 Does Not Exists



Open in new window

Question by:kulisncc
    LVL 66

    Accepted Solution

    If %ErrorLevel%==0 goto Exists  
    If %ErrorLevel%==1 goto Not_Exists  

    Author Comment

    ahhh geez - I should've thought of that. I will give it a shot and let  you know. Thanks dude.
    LVL 66

    Expert Comment

    GL with it..  :)

    Author Comment

    it worked. thanks
    LVL 66

    Expert Comment

    Anytime.. :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
    As a long-time IT Professional, the most important skill I have developed and consider to be my most valuable tool is Effective Troubleshooting. Step through my problem-solving procedure in this 10-step guide adapted from The Universal Troubleshooti…
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now