<job id="Install-MicrosoftVisualC++x86x64">
<script language="VBScript" src="..\..\scripts\ZTIUtility.vbs"/>
<script language="VBScript"> 

'//----------------------------------------------------------------------------
'// Purpose: Used to install Microsoft Visual C++ Redistributable Packages
'// Usage: cscript Install-MicrosoftVisualC++x86x64.wsf [/debug:true]
'// Version: 1.1 - August 8, 2012 - Johan Arwidmark
'// Version: 2.1 - June 26, 2014 - Mikael Nystrom
'// This script is provided "AS IS" with no warranties, confers no rights and 
'// is not supported by the authors. 
'//----------------------------------------------------------------------------

Option Explicit 
Dim iRetVal 

'On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0 

'//---------------------------------------------------------------------------
'// Function: ZTIProcess()
'//---------------------------------------------------------------------------
Function ZTIProcess() 

	oLogging.CreateEntry oUtility.ScriptName & ": Starting installation", LogTypeInfo

	Dim sSetupFile2005x86
	Dim sSetupFile2005x64
	Dim sSetupFile2008x86
	Dim sSetupFile2008x64
	Dim sSetupFile2010x86
	Dim sSetupFile2010x64
	Dim sSetupFile2012x86
	Dim sSetupFile2012x64
	Dim sSetupFile2013x86
	Dim sSetupFile2013x64
	Dim sSetupFile2015x86
	Dim sSetupFile2015x64
	

	Dim sArguments

	'// Disable Zone Checks
	oEnv("SEE_MASK_NOZONECHECKS") = 1 		

	sSetupFile2005x86 = oUtility.ScriptDir & "\Source\VC2005\vcredist_x86.exe"
	sSetupFile2005x64 = oUtility.ScriptDir & "\Source\VC2005\vcredist_x64.exe"
	sSetupFile2008x86 = oUtility.ScriptDir & "\Source\VC2008\vcredist_x86.exe"
	sSetupFile2008x64 = oUtility.ScriptDir & "\Source\VC2008\vcredist_x64.exe"
	sSetupFile2010x86 = oUtility.ScriptDir & "\Source\VC2010\vcredist_x86.exe"
	sSetupFile2010x64 = oUtility.ScriptDir & "\Source\VC2010\vcredist_x64.exe"
	sSetupFile2012x86 = oUtility.ScriptDir & "\Source\VC2012\vcredist_x86.exe"
	sSetupFile2012x64 = oUtility.ScriptDir & "\Source\VC2012\vcredist_x64.exe"
	sSetupFile2013x86 = oUtility.ScriptDir & "\Source\VC2013\vcredist_x86.exe"
	sSetupFile2013x64 = oUtility.ScriptDir & "\Source\VC2013\vcredist_x64.exe"
	sSetupFile2015x86 = oUtility.ScriptDir & "\Source\VC2015\vc_redist.x86.exe"
	sSetupFile2015x64 = oUtility.ScriptDir & "\Source\VC2015\vc_redist.x64.exe"
	
	sArguments = "/Q"

	'Checking for x86 files
	If not oFSO.FileExists(sSetupFile2005x86) then
		oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2005x86 & " was not found, unable to install", LogTypeError
		ZTIProcess = Failure
		Exit Function
	End if

	If not oFSO.FileExists(sSetupFile2008x86) then
		oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2008x86 & " was not found, unable to install", LogTypeError
		ZTIProcess = Failure
		Exit Function
	End if

	If not oFSO.FileExists(sSetupFile2010x86) then
		oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2010x86 & " was not found, unable to install", LogTypeError
		ZTIProcess = Failure
		Exit Function
	End if

	If not oFSO.FileExists(sSetupFile2012x86) then
		oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2012x86 & " was not found, unable to install", LogTypeError
		ZTIProcess = Failure
		Exit Function
	End if

	If not oFSO.FileExists(sSetupFile2013x86) then
		oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2013x86 & " was not found, unable to install", LogTypeError
		ZTIProcess = Failure
		Exit Function
	End if

	If not oFSO.FileExists(sSetupFile2015x86) then
		oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2015x86 & " was not found, unable to install", LogTypeError
		ZTIProcess = Failure
		Exit Function
	End if


	'Installing x86 files
	oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2005x86, LogTypeInfo
	
	iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2005x86 & """ " & sArguments)
	
	if (iRetVal = 0) or (iRetVal = 3010) then
		ZTIProcess = Success 
	Else 
		ZTIProcess = Failure
	End If
	
	oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
	oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

	oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2008x86, LogTypeInfo
	iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2008x86 & """ " & sArguments)
	
	if (iRetVal = 0) or (iRetVal = 3010) then
		ZTIProcess = Success 
	Else 
		ZTIProcess = Failure
	End If
	
	oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
	oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

	oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2010x86, LogTypeInfo
	iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2010x86 & """ " & sArguments)
	
	if (iRetVal = 0) or (iRetVal = 3010) then
		ZTIProcess = Success 
	Else 
		ZTIProcess = Failure
	End If
	
	oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
	oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

	oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2012x86, LogTypeInfo
	iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2012x86 & """ " & sArguments)
	
	if (iRetVal = 0) or (iRetVal = 3010) then
		ZTIProcess = Success 
	Else 
		ZTIProcess = Failure
	End If
	
	oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
	oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

	oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2013x86, LogTypeInfo
	iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2013x86 & """ " & sArguments)
	
	if (iRetVal = 0) or (iRetVal = 3010) then
		ZTIProcess = Success 
	Else 
		ZTIProcess = Failure
	End If
	
	oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
	oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo
	
	oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2013x86, LogTypeInfo
	iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2015x86 & """ " & sArguments)
	
	if (iRetVal = 0) or (iRetVal = 3010) then
		ZTIProcess = Success 
	Else 
		ZTIProcess = Failure
	End If
	
	oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
	oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo
	
	' If x64 operating system, also install x64 version	
	If oEnvironment.Item("Architecture") = "X64" then

		'Checking for x64 files
		If not oFSO.FileExists(sSetupFile2005x64) then
			oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2005x64 & " was not found, unable to install", LogTypeError
			ZTIProcess = Failure
			Exit Function
		End if

		If not oFSO.FileExists(sSetupFile2008x64) then
			oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2008x64 & " was not found, unable to install", LogTypeError
			ZTIProcess = Failure
			Exit Function
		End if

		If not oFSO.FileExists(sSetupFile2010x64) then
			oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2010x64 & " was not found, unable to install", LogTypeError
			ZTIProcess = Failure
			Exit Function
		End if

		If not oFSO.FileExists(sSetupFile2012x64) then
			oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2012x64 & " was not found, unable to install", LogTypeError
			ZTIProcess = Failure
			Exit Function
		End if

		If not oFSO.FileExists(sSetupFile2013x64) then
			oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2013x64 & " was not found, unable to install", LogTypeError
			ZTIProcess = Failure
			Exit Function
		End if

		If not oFSO.FileExists(sSetupFile2015x64) then
			oLogging.CreateEntry oUtility.ScriptName & ": " & sSetupFile2015x64 & " was not found, unable to install", LogTypeError
			ZTIProcess = Failure
			Exit Function
		End if

		'Installing x64 files
		oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2005x64, LogTypeInfo
		iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2005x64 & """ " & sArguments)
		
		if (iRetVal = 0) or (iRetVal = 3010) then
			ZTIProcess = Success 
		Else 
			ZTIProcess = Failure
		End If
		
		oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
		oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

		oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2008x64, LogTypeInfo
		iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2008x64 & """ " & sArguments)
		
		if (iRetVal = 0) or (iRetVal = 3010) then
			ZTIProcess = Success 
		Else 
			ZTIProcess = Failure
		End If
		
		oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
		oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

		oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2010x64, LogTypeInfo
		iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2010x64 & """ " & sArguments)
		
		if (iRetVal = 0) or (iRetVal = 3010) then
			ZTIProcess = Success 
		Else 
			ZTIProcess = Failure
		End If
		
		oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
		oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

		oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2012x64, LogTypeInfo
		iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2012x64 & """ " & sArguments)
		
		if (iRetVal = 0) or (iRetVal = 3010) then
			ZTIProcess = Success 
		Else 
			ZTIProcess = Failure
		End If
		
		oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
		oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

		oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2013x64, LogTypeInfo
		iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2013x64 & """ " & sArguments)
		
		if (iRetVal = 0) or (iRetVal = 3010) then
			ZTIProcess = Success 
		Else 
			ZTIProcess = Failure
		End If
		
		oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
		oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

		oLogging.CreateEntry oUtility.ScriptName & ": About to install " & sSetupFile2013x64, LogTypeInfo
		iRetVal = oUtility.RunWithHeartbeat("""" & sSetupFile2015x64 & """ " & sArguments)
		
		if (iRetVal = 0) or (iRetVal = 3010) then
			ZTIProcess = Success 
		Else 
			ZTIProcess = Failure
		End If
		
		oLogging.CreateEntry oUtility.ScriptName & ": Return code from command = " & iRetVal, LogTypeInfo
		oLogging.CreateEntry oUtility.ScriptName & ": Finished installation", LogTypeInfo

	End If

	'/// Enable Zone Checks
	oEnv.Remove("SEE_MASK_NOZONECHECKS")
	
End Function 

</script>
</job>