Batch file to install software -- only if not already installed

Is there a way to write a batch file to locate a particular EXE?  If not present it will proceed with the setup of a program... if present it will simply terminate?
cloilAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Frosty555Commented:
You would do it using the IF NOT EXIST command, like the example below:

if not exist "C:\program files\some folder\someprogram.exe" goto doit
goto cancel
 
:doit
    echo  perform installation
    goto exit
 
:cancel
    echo exe found. refuse to install.
    goto exit
 
:exit
    echo script is finished.

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Frosty555Commented:
Keep in mind the above script will not help you if the user installed the software somewhere OTHER than the location you are checking. If you happen to know what the software's "uninstall" entry in the registry will be called, you can use the REG command to check if it exists in the registry.

Use REGEDIT to look at the registry key HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, and you'll see a list of uninstall programs that will appear in Add/Remove Programs. If you can figure out what the software you're installing will put in there, you can use the script below to check if it exists.
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\YourAppName" > nul
if errorlevel 1 goto doit
if errorlevel 0 goto cancel
 
:doit
    echo  perform installation
    goto exit
 
:cancel
    echo exe found. refuse to install.
    goto exit
 
:exit
    echo script is finished.

Open in new window

0
jjreeseCommented:
How can you modify this to make it install the program if it is not already installed?
Under the :doit list the path to the setup.exe???
0
Frosty555Commented:
Yes, in the :doit label is where you would execute the installer. Either run the setup.exe, or run the MSI using msiexec.exe, or run whatever you would normally have to run to install the software.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.