anchor.diff:  :install
   @rem Install Chef using chef-client MSI installer
   
  -@set "REMOTE_SOURCE_MSI_URL=https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%"
  +<% url="https://www.opscode.com/chef/download?p=windows&pv=%MACHINE_OS%&m=%MACHINE_ARCH%" -%>
  +<% url += "&v=#{@config[:bootstrap_version]}" if @config.key? :bootstrap_version -%>
  +@set "REMOTE_SOURCE_MSI_URL=<%= url %>"
   @set "LOCAL_DESTINATION_MSI_PATH=<%= local_download_path %>"
  +@set "CHEF_CLIENT_MSI_LOG_PATH=%TEMP%\chef-client-msi%RANDOM%.log"
   @set "FALLBACK_QUERY_STRING=&DownloadContext=PowerShell"
   
  +@rem Clear any pre-existing downloads
  +@echo Checking for existing downloaded package at "%LOCAL_DESTINATION_MSI_PATH%"
  +@if EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
  +    @echo Found existing downloaded package, deleting.
  +    @del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
  +    @if ERRORLEVEL 1 (
  +        echo Warning: Failed to delete pre-existing package with status code !ERRORLEVEL! > "&2"
  +    )
  +) else (
  +    echo No existing downloaded packages to delete.
  +)
  +
  +@rem If there's somehow a name collision, remove pre-existing log
  +@if EXIST "%CHEF_CLIENT_MSI_LOG_PATH%" del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
  +
  +@echo Attempting to download client package using cscript...
   cscript /nologo <%= bootstrap_directory %>\wget.vbs /url:"%REMOTE_SOURCE_MSI_URL%" /path:"%LOCAL_DESTINATION_MSI_PATH%"
   
   @rem Work around issues found in Windows Server 2012 around job objects not respecting WSMAN memory quotas
   @rem that cause the MSI download process to exceed the quota even when it is increased by administrators.
   @rem Retry the download using a more memory-efficient mechanism that only works if PowerShell is available.
  -@if ERRORLEVEL 1 (      
  -    echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
  -    echo Warning: Retrying download with PowerShell if available
  -    if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
  -    @powershell -ExecutionPolicy Unrestricted -NoProfile -NonInteractive "& '<%= bootstrap_directory %>\wget.ps1' '%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%' '%LOCAL_DESTINATION_MSI_PATH%'"
  -
  -    if NOT ERRORLEVEL 1 (
  -        echo Download succeeded
  +@set DOWNLOAD_ERROR_STATUS=!ERRORLEVEL!
  +@if ERRORLEVEL 1 (
  +    @echo Failed cscript download with status code !DOWNLOAD_ERROR_STATUS! > "&2"
  +    @if !DOWNLOAD_ERROR_STATUS!==0 set DOWNLOAD_ERROR_STATUS=2
  +) else (
  +    @rem Sometimes the error level is not set even when the download failed,
  +    @rem so check for the file to be sure it is there -- if it's not, we'll retry
  +    @if NOT EXIST "%LOCAL_DESTINATION_MSI_PATH%" (
  +        echo Failed download: download completed, but downloaded file not found > "&2"
  +        set DOWNLOAD_ERROR_STATUS=2
       ) else (
  -        echo Failed to download "%REMOTE_SOURCE_MSI_URL%"
  -        echo Subsequent attempt to install the downloaded MSI is likely to fail
  +        echo Download via cscript succeeded.
       )
   )
   
  +@if NOT %DOWNLOAD_ERROR_STATUS%==0 (
  +    @echo Warning: Failed to download "%REMOTE_SOURCE_MSI_URL%" to "%LOCAL_DESTINATION_MSI_PATH%"
  +    @echo Warning: Retrying download with PowerShell if available...
  +
  +    @if EXIST "%LOCAL_DESTINATION_MSI_PATH%" del /f /q "%LOCAL_DESTINATION_MSI_PATH%"
  +
  +    @set powershell_download=powershell.exe -ExecutionPolicy Unrestricted -NoProfile -NonInteractive -command "& '<%= bootstrap_directory %>\wget.ps1' '%REMOTE_SOURCE_MSI_URL%%FALLBACK_QUERY_STRING%' '%LOCAL_DESTINATION_MSI_PATH%'"
  +    @echo !powershell_download!
  +    @call !powershell_download!
  +    @if NOT ERRORLEVEL 1 (
  +        echo Download via PowerShell succeeded.
  +    ) else (
  +        echo Failed to download "%REMOTE_SOURCE_MSI_URL%" with status code !ERRORLEVEL!. > "&2"
  +        echo Exiting without bootstrapping due to download failure. > "&2"
  +        exit /b 1
  +    )
  +)
  +
  +@echo Installing downloaded client package...
  +
   <%= install_chef %>
   
  +@if ERRORLEVEL 1 (
  +    echo Chef-client package failed to install with status code !ERRORLEVEL!. > "&2"
  +    echo See installation log for additional detail: %CHEF_CLIENT_MSI_LOG_PATH%. > "&2"
  +) else (
  +    @echo Installation completed successfully
  +    del /f /q "%CHEF_CLIENT_MSI_LOG_PATH%"
  +)
  +
   @endlocal
  +
  +@echo off
  +echo Writing validation key...
   
   > <%= bootstrap_directory %>\validation.pem (
    <%= validation_key %>
   )
  +
  +echo Validation key written.
  +@echo on
   
   <% if @config[:encrypted_data_bag_secret] -%>
   > <%= bootstrap_directory %>\encrypted_data_bag_secret (
  
positive.code: echo server.start >>C:\chef_zero_startup.rb
  C:\opscode\chef\embedded\bin\ruby C:\chef_zero_startup.rb
  
  <%= start_chef %>
  
  
negative.code: 
  @rem Determine the version and the architecture
  
  @FOR /F "tokens=1-8 delims=.[] " %%A IN ('ver') DO (
  @set WinMajor=%%D
  @set WinMinor=%%E
  @set WinBuild=%%F
  )
  
  @echo Detected Windows Version %WinMajor%.%WinMinor% Build %WinBuild%
  
  @set LATEST_OS_VERSION_MAJOR=6
  @set LATEST_OS_VERSION_MINOR=3
  
  @if /i %WinMajor% GTR %LATEST_OS_VERSION_MAJOR% goto VersionUnknown
  @if /i %WinMajor% EQU %LATEST_OS_VERSION_MAJOR%  (
    @if /i %WinMinor% GTR %LATEST_OS_VERSION_MINOR% goto VersionUnknown
  )
  
  goto Version%WinMajor%.%WinMinor%
  
  :VersionUnknown
  @rem If this is an unknown version of windows set the default
  @set MACHINE_OS=2008r2
  @echo Warning: Unknown version of Windows, assuming default of Windows %MACHINE_OS%
  goto architecture_select
  
  :Version6.0
  @set MACHINE_OS=2008
  goto architecture_select
  
  :Version5.2
  @set MACHINE_OS=2003r2
  goto architecture_select
  
  :Version6.1
  @set MACHINE_OS=2008r2
  goto architecture_select
  
  :Version6.2
  @set MACHINE_OS=2012
  goto architecture_select
  
  @rem Currently Windows Server 2012 R2 is treated as equivalent to Windows Server 2012 
  :Version6.3
  goto Version6.2
  
  :architecture_select
  goto Architecture%PROCESSOR_ARCHITEW6432%
  
  :Architecture
  goto Architecture%PROCESSOR_ARCHITECTURE%
  
  @rem If this is an unknown architecture set the default
  