anchor.diff:  ::::::::::::
   :main
   ::::::::::::
  +
  +:: Get the PlatformVersion from SystemInfo
  +for /f "delims=:; tokens=1,2" %%a in ('systeminfo') do (
  +  if "%%a" == "OS Version" set "PlatformVersionRow=%%b"
  +)
  +
  +:: Extract the major/minor version (stripped)
  +for /f "delims=.; tokens=1,2,3" %%a in ("%PlatformVersionRow%") do (
  +  for /f "tokens=1" %%v in ("%%a") do set "PlatformVersionMajor=%%v"
  +  for /f "tokens=1" %%v in ("%%b") do set "PlatformVersionMinor=%%v"
  +  for /f "tokens=1" %%v in ("%%c") do set "PlatformVersionRelease=%%v"
  +)
  +
  +:: Get the PlatformFlavor from SystemInfo
  +for /f "delims=:; tokens=1,2" %%a in ('systeminfo') do (
  +  if "%%a" == "OS Name" set "PlatformFlavorRow=%%b"
  +)
  +
  +:: Detect whether we're using a server or client flavor
  +for /f "tokens=1,2,3" %%a in ("%PlatformFlavorRow%") do if "%%a" == "Microsoft" if "%%b" == "Windows" if "%%c" == "Server" (
  +  set "PlatformFlavor=Server"
  +) else (
  +  set "PlatformFlavor=Client"
  +)
  +
  +echo ==^> Detected Windows Platform Version ^(%PlatformFlavor%^): %PlatformVersionMajor%.%PlatformVersionMinor%.%PlatformVersionRelease%
  +
  +:: Figure out the build type
   echo "%PACKER_BUILDER_TYPE%" | findstr /i "vmware" >nul
   if not errorlevel 1 goto vmware
   echo "%PACKER_BUILDER_TYPE%" | findstr /i "vsphere" >nul
  
positive.code:   echo ==^> Detected virtualization platform ^(x64^): VMware
  )
  
  for %%i in ("%VMWARE_TOOLS_TAR_URL%") do set VMWARE_TOOLS_TAR=%%~nxi
  set "VMWARE_TOOLS_DIR=%TEMP%\vmware"
  set "VMWARE_TOOLS_TAR_PATH=%VMWARE_TOOLS_DIR%\%VMWARE_TOOLS_TAR%"
  set "VMWARE_TOOLS_ISO=windows.iso"
  echo ==^> Installing the VMware tools with directory %VMWARE_TOOLS_DIR%
  
  mkdir "%VMWARE_TOOLS_DIR%"
  pushd "%VMWARE_TOOLS_DIR%"
  set VMWARE_TOOLS_SETUP_PATH=
  
  :vmware_tools_setup_path_search
  @for %%i in (%PACKER_SEARCH_PATHS%) do @if not defined VMWARE_TOOLS_SETUP_PATH @if exist "%%~i\VMwareToolsUpgrader.exe" set VMWARE_TOOLS_SETUP_PATH=%%~i\%VMWARE_TOOLS_SETUP_EXE%
  if defined VMWARE_TOOLS_SETUP_PATH goto install_vmware_tools
  :: vmware_tools_setup_path_search isn't defined
  :: if not defined VMWARE_TOOLS_SETUP_PATH ( if defined VMWARE_TOOLS_MOUNTED goto vmware_tools_setup_path_search )
  set VMWARE_TOOLS_ISO_PATH=
  @for %%i in (%PACKER_SEARCH_PATHS%) do @if not defined VMWARE_TOOLS_ISO_PATH @if exist "%%~i\%VMWARE_TOOLS_ISO%" set VMWARE_TOOLS_ISO_PATH=%%~i\%VMWARE_TOOLS_ISO%
  
  :: if windows.iso is zero bytes, then download it
  set _VMWARE_TOOLS_SIZE=0
  if defined VMWARE_TOOLS_ISO_PATH for %%i in (%VMWARE_TOOLS_ISO_PATH%) do set _VMWARE_TOOLS_SIZE=%%~zi
  if %_VMWARE_TOOLS_SIZE% EQU 0 set VMWARE_TOOLS_ISO_PATH=
  
  if defined VMWARE_TOOLS_ISO_PATH goto install_vmware_tools_from_iso
  
  call "%SystemRoot%\_download.cmd" "%VMWARE_TOOLS_TAR_URL%" "%VMWARE_TOOLS_TAR_PATH%"
  if errorlevel 1 (
    echo ==^> ERRROR: Unable to download file from %VMWARE_TOOLS_TAR_URL%
    goto exit1
  )
  
  if not exist "%VMWARE_TOOLS_TAR_PATH%" goto exit1
  
  call :install_sevenzip
  if errorlevel 1 goto exit1
  7z e -y -o"%VMWARE_TOOLS_DIR%" "%VMWARE_TOOLS_TAR_PATH%" *tools-windows*
  if exist  "%VMWARE_TOOLS_DIR%\*.iso" (
  	ren  "%VMWARE_TOOLS_DIR%\*.iso" "windows.iso"
  	set VMWARE_TOOLS_ISO_PATH=%VMWARE_TOOLS_DIR%\%VMWARE_TOOLS_ISO%
  )
  if defined VMWARE_TOOLS_ISO_PATH goto install_vmware_tools_from_iso
  
  @if errorlevel 1 echo ==^> WARNING: Error %ERRORLEVEL% was returned by: 7z e "%VMWARE_TOOLS_TAR_PATH%"
  ver>nul
  set VMWARE_TOOLS_INSTALLER_PATH=
  for %%i in ("%VMWARE_TOOLS_DIR%\tools-windows-*.exe") do set VMWARE_TOOLS_INSTALLER_PATH=%%~i
  if not exist "%VMWARE_TOOLS_INSTALLER_PATH%" echo ==^> ERROR: Failed to unzip "%VMWARE_TOOLS_TAR_PATH%" & goto exit1
  
  echo ==^> Installing VMware tools with %VMWARE_TOOLS_INSTALLER_PATH%
  "%VMWARE_TOOLS_INSTALLER_PATH%" /s
  
  set VMWARE_TOOLS_PROGRAM_FILES_ISO=
  if not exist "%VMWARE_TOOLS_PROGRAM_FILES_DIR%" echo ==^> ERROR: Directory not found: "%VMWARE_TOOLS_PROGRAM_FILES_DIR%" & goto exit1
  for /r "%VMWARE_TOOLS_PROGRAM_FILES_DIR%" %%i in (%VMWARE_TOOLS_ISO%) do if exist "%%~i" set VMWARE_TOOLS_PROGRAM_FILES_ISO=%%~i
  if not exist "%VMWARE_TOOLS_PROGRAM_FILES_ISO%" echo ==^> ERROR: File not found: "%VMWARE_TOOLS_ISO%" in "%VMWARE_TOOLS_PROGRAM_FILES_DIR%" & goto exit1
  
  set "VMWARE_TOOLS_ISO_PATH=%VMWARE_TOOLS_DIR%\%VMWARE_TOOLS_ISO%"
  copy /y "%VMWARE_TOOLS_PROGRAM_FILES_ISO%" "%VMWARE_TOOLS_ISO_PATH%"
  if not exist "%VMWARE_TOOLS_ISO_PATH%" echo ==^> ERROR: File not found: "%VMWARE_TOOLS_ISO_PATH%" & goto exit1
  
  rmdir /q /s "%VMWARE_TOOLS_PROGRAM_FILES_DIR%\tools-windows" || ver>nul
  rmdir "%VMWARE_TOOLS_PROGRAM_FILES_DIR%" || ver>nul
  
  :install_vmware_tools_from_iso
  call :install_sevenzip
  if errorlevel 1 goto exit1
  
  echo ==^> Extracting the VMware Tools installer to %VMWARE_TOOLS_DIR% from %VMWARE_TOOLS_ISO_PATH%
  7z e -o"%VMWARE_TOOLS_DIR%" "%VMWARE_TOOLS_ISO_PATH%" "%VMWARE_TOOLS_SETUP_EXE%"
  @if errorlevel 1 echo ==^> WARNING: Error %ERRORLEVEL% was returned by: 7z e -o"%VMWARE_TOOLS_DIR%" "%VMWARE_TOOLS_ISO_PATH%" "%VMWARE_TOOLS_SETUP_EXE%"
  ver>nul
  set "VMWARE_TOOLS_SETUP_PATH=%VMWARE_TOOLS_DIR%\%VMWARE_TOOLS_SETUP_EXE%"
  if not exist "%VMWARE_TOOLS_SETUP_PATH%" echo ==^> Unable to unzip "%VMWARE_TOOLS_ISO_PATH%" & goto exit1
  
  :install_vmware_tools
  echo ==^> Installing VMware tools with %VMWARE_TOOLS_SETUP_PATH%
  "%VMWARE_TOOLS_SETUP_PATH%" /S /v "/qn REBOOT=R ADDLOCAL=ALL"
  
negative.code: if not defined SEVENZIP_32_URL set SEVENZIP_32_URL=http://7-zip.org/a/7z1604.msi
  if not defined SEVENZIP_64_URL set SEVENZIP_64_URL=http://7-zip.org/a/7z1604-x64.msi
  if not defined VBOX_ISO_URL set VBOX_ISO_URL=http://download.virtualbox.org/virtualbox/5.1.30/VBoxGuestAdditions_5.1.30.iso
  if not defined VMWARE_TOOLS_LATEST_ISOURL set VMWARE_TOOLS_LATEST_ISOURL=https://packages.vmware.com/tools/releases/11.1.0/windows/VMware-tools-windows-11.1.0-16036546.iso
  if not defined VMWARE_TOOLS_OLD_ISOURL set VMWARE_TOOLS_OLD_ISOURL=https://packages.vmware.com/tools/releases/10.2.5/windows/VMware-tools-windows-10.2.5-8068406.iso
  goto main
  
  ::::::::::::
  