title: Batch Script: IF NOT EXIST fails for file check when executed through wix ExePackage
body: <p>I am executing a batch file to check if particular file is present or not using <code>IF NOT EXIST</code> clause through wix bundle. it looks like below</p>
  
  <pre><code>@echo off
  
  set EMS_INSTALL_ROOT="C:\Program Files (x86)\TOOLS\EMS\swVersion.txt"
  
  IF NOT EXIST "%EMS_INSTALL_ROOT%" (
      exit 1
  )
  
  set /p Version=&lt;"%EMS_INSTALL_ROOT%"
  REG ADD HKCU\CurrentSwVersion /v SwVersion /t REG_SZ /d %VERSION% /f
  
  exit 0
  </code></pre>
  
  <p>and the bundle.wxs file looks like</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
        xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"
        xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"&gt;
  
      &lt;Bundle Name='Language Installer 1.0'
          Version='1.0'
          UpgradeCode='{CFA901F4-F22D-4826-AF17-CEF08636626A}'
          Manufacturer='xxx'&gt;
  
          &lt;BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense"&gt;
              &lt;bal:WixStandardBootstrapperApplication 
                  LicenseFile="license.rtf"
                  SuppressOptionsUI ="yes"
                  /&gt;
          &lt;/BootstrapperApplicationRef&gt;
  
          &lt;Chain&gt;
              &lt;ExePackage SourceFile="sw_version_check.bat" Compressed="yes"/&gt;
              &lt;MsiPackage SourceFile="multilang.msi" Compressed="yes" DisplayInternalUI='yes'/&gt;
          &lt;/Chain&gt;
      &lt;/Bundle&gt;
  &lt;/Wix&gt;
  </code></pre>
  
  <p>So, when i execute the same batch file form outside, like on command prompt it <code>returns 0</code> and when i run the same through bundle it <code>returns 1</code>. 
  This is the log that i get from bundle </p>
  
  <pre><code>[1140:00EC][2017-11-10T09:46:46]i305: Verified acquired payload: sw_version_check.bat at path: C:\ProgramData\Package Cache\.unverified\sw_version_check.bat, moving to: C:\ProgramData\Package Cache\F791A31D2DE729790CB77093BD38CF43E3FDA802\sw_version_check.bat.
  [1140:00EC][2017-11-10T09:46:46]i304: Verified existing payload: multilang.msi at path: C:\ProgramData\Package Cache\{EBB4657C-1AE5-423A-B2E4-2F0E6738BF2F}v1.0.0.0\multilang.msi.
  [1140:0E20][2017-11-10T09:46:46]i301: Applying execute package: sw_version_check.bat, action: Install, path: C:\ProgramData\Package Cache\F791A31D2DE729790CB77093BD38CF43E3FDA802\sw_version_check.bat, arguments: '"C:\ProgramData\Package Cache\F791A31D2DE729790CB77093BD38CF43E3FDA802\sw_version_check.bat"'
  [1140:0E20][2017-11-10T09:46:46]e000: Error 0x80070001: Process returned error: 0x1
  [1140:0E20][2017-11-10T09:46:46]e000: Error 0x80070001: Failed to execute EXE package.
  [0DB8:0DC8][2017-11-10T09:46:46]e000: Error 0x80070001: Failed to configure per-machine EXE package.
  [0DB8:0DC8][2017-11-10T09:46:46]i319: Applied execute package: sw_version_check.bat, result: 0x80070001, restart: None
  [0DB8:0DC8][2017-11-10T09:46:46]e000: Error 0x80070001: Failed to execute EXE package.
  </code></pre>
  
  <p>I have even tried to <code>run as admin</code> on bundle.exe but getting same result.</p>
  
  <p>So, Could some one tell me what i am doing wrong here?</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>As per the suggestion by @Squashman i made change in the example script and it worked but the same thing i applied for my dynamic script it again started failing. it looks like</p>
  
  <pre><code>@echo off
  
  FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY "HKLM\SOFTWARE\MANBW" /v "ROOT" 2^&gt;nul`) DO (
      set ValueName=%%A
      set ValueType=%%B
      set "ECS_INSTALL_ROOT=%%CswVersion.txt"
  )
  
  IF NOT EXIST "%ECS_INSTALL_ROOT%" (
      exit 1
  )
  
  set /p Version=&lt;"%ECS_INSTALL_ROOT%"
  REG ADD HKCU\CurrentSwVersion /v SwVersion /t REG_SZ /d %VERSION% /f
  
  exit 0
  </code></pre>
  
  <p>Sorry to bother once again. Please tell me am i applying the suggesting of @Squashman properly in my dynamic script? Please help i have spent 5-6 hrs to make trial and error.</p>