Q. How can I only perform an action in a batch file if a file doesn't exist?
John Savill
March 31, 2010
1 Min Read
A. Leading on from my previous FAQ about installing based on architecture version, the next requirement was to only install the agent if it weren't already installed. This can be achieved in a number of ways, but the easiest was to just look for the DPM client user interface executable and, if found, skip the entire batch file.
To do this, just use
if exist goto :
If you want to do something if a file doesn't exist, use
if not exist goto :
My updated agent installation script became:
@echo off
echo Checking for DPM agent
if exist "C:Program FilesMicrosoft Data Protection ManagerDPMbinDPMClientUI.exe" goto EXIT
echo Detecting OS processor type
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT
echo 32-bit OS
\savdaldpm01ProtectionAgentsRA3.0.7558.0i386DPMAgentInstaller_x86 /q
goto SETSERV
:64BIT
echo 64-bit OS
\savdaldpm01ProtectionAgentsRA3.0.7558.0amd64DPMAgentInstaller_x64 /q
:SETSERV
"C:Program FilesMicrosoft Data Protection ManagerDPMbinsetdpmserver.exe" -dpmservername savdaldpm01.savilltech.net
:EXIT
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like