[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2280
  • 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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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