@ECHO OFF

:: Workaround for Installation Incomplete due to issues with Microsoft Visual C++ 2010  x86/x64 Redistributable
:: Version 1.5

ECHO This tool will attempt to correct the Microsoft 
ECHO Visual C++ 2010 x86/x64 Redistributable Package(s)
ECHO Running from %~dp0

PAUSE

SET CURRENTDIR=%~dp0
SET ATL=%WINDIR%\SYSTEM32\atl100.dll
SET VCP=%WINDIR%\SYSTEM32\msvcp100.dll 
SET VCR=%WINDIR%\SYSTEM32\msvcr100.dll
SET THIS=%RANDOM%
SET ERRORLEVEL=0

IF EXIST %ATL% REN %ATL% atl100.dl%THIS%
IF EXIST %VCP% REN %VCP% msvcp100.dl%THIS%
IF EXIST %VCR% REN %VCR% msvcr100.dl%THIS%

IF "%processor_architecture%" NEQ "AMD64" GOTO X86

REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1D8E6291-B0D5-35EC-8441-6616F567A0F7}>nul 2>&1
IF %ERRORLEVEL%==0 (SET AMD_64=TRUE) ELSE (SET AMD_64=FALSE)
IF %AMD_64%==FALSE GOTO INST_64x64
START /WAIT MsiExec.exe /X{1D8E6291-B0D5-35EC-8441-6616F567A0F7}

:INST_64x64
IF NOT EXIST "%CURRENTDIR%vcredist_x64.exe" GOTO FNF_X64
CD /D "%CURRENTDIR%"
START /WAIT vcredist_x64.exe

:X64
SET ERRORLEVEL=0
REG QUERY HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}>nul 2>&1
IF %ERRORLEVEL%==0 (SET AMD_64x86=TRUE) ELSE (SET AMD_64x86=FALSE)
IF %AMD_64x86%==FALSE GOTO INST_64x86
START /WAIT MsiExec.exe /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}

:INST_64x86
IF NOT EXIST "%CURRENTDIR%vcredist_x86.exe" GOTO FNF_X64x86
CD /D "%CURRENTDIR%"
START /WAIT vcredist_x86.exe
GOTO END

:X86
:: TEST FOR x86 VS 2010 C++ Runtime
REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}>nul 2>&1
IF %ERRORLEVEL%==0 (SET X_86=TRUE) ELSE (SET X_86=FALSE)
IF %X_86%==FALSE GOTO INST_X86
START /WAIT MsiExec.exe /X{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5} 

:INST_X86
IF NOT EXIST "%CURRENTDIR%vcredist_x86.exe" GOTO FNF_x86
CD /D "%CURRENTDIR%"
START /WAIT vcredist_x86.exe
GOTO END

:FNF_X64
ECHO %CURRENTDIR%vcredist_x64.exe is not on the system. 
GOTO X64

:FNF_X64x86
ECHO %CURRENTDIR%VCREDIST_X86.EXE is not on the system. 
GOTO END

:FNF_x86
ECHO %CURRENTDIR%VCREDIST_X86.EXE is not on the system. 

:END
ECHO All tasks completed 
PAUSE
EXIT