Q. How can I only perform an action in a batch file if a file doesn't exist?

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 <file> goto <label>:

If you want to do something if a file doesn't exist, use

if not exist <file> goto <label>:

My updated agent installation script became:

@echo off
echo Checking for DPM agent
if exist "C:\Program Files\Microsoft Data Protection Manager\DPM\bin\DPMClientUI.exe" goto EXIT

echo Detecting OS processor type

echo 32-bit OS
\\savdaldpm01\ProtectionAgents\RA\3.0.7558.0\i386\DPMAgentInstaller_x86 /q

echo 64-bit OS
\\savdaldpm01\ProtectionAgents\RA\3.0.7558.0\amd64\DPMAgentInstaller_x64 /q

"C:\Program Files\Microsoft Data Protection Manager\DPM\bin\setdpmserver.exe" -dpmservername savdaldpm01.savilltech.net

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.