• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3312
  • Last Modified:

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?
0
cloil
Asked:
cloil
  • 3
2 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now