Monday 4 July 2016

Deploy Internet Explorer 11 with vbs





The following .VBS file can be use to deploy IE 11 with all updates and selected languages (ex english and spanish)  :

Option Explicit
'On Error Resume Next

Const strComputer = "."
Dim oParamDict : Set oParamDict = CreateObject("Scripting.Dictionary")
Dim kErrorSuccess : kErrorSuccess = "Ok"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell : Set objShell = CreateObject("WScript.Shell")
Dim objEnv : Set objEnv = objShell.Environment("Process")
Dim strScriptPath : strScriptPath = objFSO.GetParentFolderName(WScript.ScriptFullName)
Dim LogFile
Dim Return, KBname
Dim logName : logName = "Microsoft_Internet_Explorer_11_Prerequisites.log"
Dim objFolder, oReg, strKeyPath
Dim strValueName, strValue, strLanguage, strArchitecture
Dim strPathArch, strPathLang

objEnv("SEE_MASK_NOZONECHECKS") = 1
logFolder : Set LogFile = objFSO.OpenTextFile("C:\ProgramData\IE11\" & logName, 8, True)
LogFile.WriteLine(vbCrLf & "---------------------------------------------------------------------------------------------------------------------" & vbCrLf)

strLanguage = InstallLanguage
strArchitecture = OSarchitecture

    '-- Folders --
    '..\bin
    '..\x64
    '      \es-ES
    '      \en-US
    '..\x86
    '      \es-ES
    '      \en-US

strPathArch = Replace(strScriptPath,"\bin","\" & strArchitecture)
strPathLang = strPathArch & "\" & strLanguage

' installs prerequisites
LogFile.WriteLine(Now & "  -(1)  Starts to install prerequisites for Internet Explorer 11 " & strArchitecture & " for Windows 7 ...")

'install patch for KB2834140-v2-x..
LogFile.WriteLine(Now & "  -(2)  Installing update KB2834140-v2-" & strArchitecture & " ...")
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2834140-v2-" & strArchitecture & ".msu /quiet /norestart",0,True)
Results("KB2834140-v2-" & strArchitecture)

'install patch for KB2670838 (graphics and imaging issues fix)
LogFile.WriteLine(Now & "  -(3)  Installing update KB2670838-" & strArchitecture & " ...")
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2670838-" & strArchitecture & ".msu /quiet /norestart",0,True)
Results("KB2670838-" & strArchitecture)   

'install patch for KB2639308
LogFile.WriteLine(Now & "  -(4) Installing update KB2639308-" & strArchitecture & " ...")
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2639308-" & strArchitecture & ".msu /quiet /norestart",0,True)
Results("KB2639308-" & strArchitecture)   

'install patch for KB2533623 (Insecure library fix)
LogFile.WriteLine(Now & "  -(5) Installing update KB2533623-" & strArchitecture & " ...")  
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2533623-" & strArchitecture & ".msu /quiet /norestart /log",0,True)  
Results("KB2533623-" & strArchitecture)

'install patch for KB2731771 (local/UTC time conversion)
LogFile.WriteLine(Now & "  -(6) Installing update KB2731771-" & strArchitecture & " ...")  
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2731771-" & strArchitecture & ".msu /quiet /norestart /log",0,True)  
Results("KB2731771-" & strArchitecture)

'install 64-bit patch for KB2729094-v2- (Segoe font fix)
LogFile.WriteLine(Now & "  -(7) Installing update KB2729094-v2-" & strArchitecture & " ...")  
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2729094-v2-" & strArchitecture & ".msu /quiet /norestart /log",0,True)  
Results("KB2729094-" & strArchitecture)

'install patch for KB2786081
LogFile.WriteLine(Now & "  -(8) Installing update KB2786081-" & strArchitecture & " ...")  
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2786081-" & strArchitecture & ".msu /quiet /norestart /log",0,True)  
Results("KB2786081-" & strArchitecture)

'install IE Support for ..) 
If strArchitecture = "x86" Then
    LogFile.WriteLine(Now & "  -(9) Installing update IE_SUPPORT_" & strArchitecture & strLanguage & " ...")
    If objFSO.FolderExists("C:\Windows\SysNative") Then  
        Return = objShell.Run("C:\Windows\SysNative\dism.exe /online /add-package /packagepath:" & _
            strPathLang & "\IE_SUPPORT_" & strArchitecture & "_ " & strPathLang & ".cab /quiet /norestart /log",0,True)  
    Else
        Return = objShell.Run("dism.exe /online /add-package /packagepath:" & strPathLang & "\IE_SUPPORT_" & _
            strArchitecture & "_" & strPathLang & ".cab /quiet /norestart /log",0,True) 
    End If
    Results("IE_SUPPORT_" & strArchitecture & "_" & strLanguage)
Else
    LogFile.WriteLine(Now & "  -(9) Installing update IE_SUPPORT_amd" & strArchitecture & strLanguage & " ...")
    If objFSO.FolderExists("C:\Windows\SysNative") Then  
        Return = objShell.Run("C:\Windows\SysNative\dism.exe /online /add-package /packagepath:" & _
            strPathLang & "\IE_SUPPORT_amd" & strArchitecture & "_" & strPathLang & ".cab /quiet /norestart /log",0,True)  
    Else
        Return = objShell.Run("dism.exe /online /add-package /packagepath:" & strPathLang & "\IE_SUPPORT_amd" & _
            strArchitecture & "_" & strPathLang & ".cab /quiet /norestart /log",0,True) 
    End If
    Results("IE_SUPPORT_amd" & strArchitecture & "_" & strLanguage)
End If

' strLanguage
' strPathLang

'install patch for KB2888049 (Improve network performance for IE11)  
LogFile.WriteLine(Now & "  -(10) Installing update KB2888049-" & strArchitecture & " ...")  
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2888049-" & strArchitecture & ".msu /quiet /norestart /log",0,True)  
Results("KB2888049-" & strArchitecture)

'install patch for KB2882822
LogFile.WriteLine(Now & "  -(11) Installing update KB2882822-" & strArchitecture & " ...")  
Return = objShell.Run("wusa.exe " & strPathArch & "\Windows6.1-KB2882822-" & strArchitecture & ".msu /quiet /norestart /log",0,True)  
Results("KB2882822-" & strArchitecture)

'Cambio de la variable idioma para que conincida con la nomenclatura de microsoft.
If strLanguage = "en-US" Then
    strLanguage = Left(strLanguage,2)
End If

'install IE Spelling
LogFile.WriteLine(Now & "  -(12) Installing update IE Spelling_ " & strLanguage & " ...")  
Return = objShell.Run("wusa.exe " & strPathLang & "\IE-Spelling-" & strLanguage & ".msu /quiet /norestart /log",0,True)  
Results("IE-Spelling-" & strLanguage)

'install IE Hyphenation
LogFile.WriteLine(Now & "  -(13) Installing update IE Hyphenation" & strLanguage & " ...")  
Return = objShell.Run("wusa.exe " & strPathLang & "\IE-Hyphenation-" & strLanguage & ".msu /quiet /norestart /log",0,True)  
Results("IE-Hyphenation-" & strLanguage)

'install Internet Explorer 11
LogFile.WriteLine(Now & "  -(14) Installing Internet Explorer 11 for " & strArchitecture & "...")  
LogFile.WriteLine(Now & "  -  The IE 11 Install log is located at :  C:\ProgramData\IE11\Microsoft_Internet_Explorer_11_" & strArchitecture & "_Install.log")

If objFSO.FolderExists("C:\Windows\SysNative") Then
    Return = objShell.Run("C:\Windows\SysNative\dism.exe /online /add-package /packagepath:" & strPathLang & _
         "\IE-Win7.CAB /quiet /norestart /logpath:C:\ProgramData\IE11\Microsoft_Internet_Explorer_11_" & _
          strArchitecture & "_Install.log",0,True) & objShell.Run("C:\Windows\SysNative\dism.exe /online /add-package /packagepath:" & strPathLang & _
         "\ielangpack-es-ES.CAB /quiet /norestart /logpath:C:\ProgramData\TIE11\Microsoft_Internet_Explorer_11_" & _
          strArchitecture & "_Install.log",0,True)
        

Else      
    Return = objShell.Run("dism.exe /online /add-package /packagepath:" & strPathLang & _
        "\IE-Win7.CAB /quiet /norestart /logpath:C:\ProgramData\IE11\Microsoft_Internet_Explorer_11_" & _
         strArchitecture & "_Install.log",0,True) & objShell.Run("dism.exe /online /add-package /packagepath:" & strPathLang & _
        "\ielangpack-es-ES.CAB /quiet /norestart /logpath:C:\ProgramData\IE11\Microsoft_Internet_Explorer_11_" & _
         strArchitecture & "_Install.log",0,True) 
End If


If Return = 3010 Then      
    LogFile.WriteLine(Now & "  -  WARNING: Installation of Internet Explorer 11 has completed successfully, however, required reboot was suppressed!")      
    WScript.Quit(0)  
ElseIf Return <> 0 Then      
    LogFile.WriteLine(Now & "  -  ERROR: Installation of Internet Explorer 11 has failed with error: " & RETURN)  
Else      
    LogFile.WriteLine(Now & "  -  Installation of Internet Explorer 11 has completed successfully.")  
End If

If kErrorSuccess <> "Ok" Then
    Usage(True)
End If

LogFile.Close
WScript.Quit(0)

'--------------------------------------------------------------------------------------------------------------------

Function InstallLanguage
    Const HKEY_LOCAL_MACHINE = &H80000002   
    'strComputer = "."   
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")   
    strKeyPath = "SYSTEM\CurrentControlSet\Control\Nls\Language"
    strValueName = "InstallLanguage"
    oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
    strValueName,strValue   
    Select Case strValue
        Case "0C0A"
        LogFile.WriteLine(Now & " - OS installation language: Spanish")   
        InstallLanguage = "es-ES"
        Case "0409"
        LogFile.WriteLine(Now & " - OS installation language: English")
        InstallLanguage = "en-US"
        Case Else
        kErrorSuccess = "Error - OS installation language not supported (" & strValue & ") only Spanish or English"           
        Usage(True)
    End Select   
End Function

Function OSarchitecture
    Const HKEY_LOCAL_MACHINE = &H80000002   
    'strComputer = "."   
    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")   
    strKeyPath = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"   
    strValueName = "PROCESSOR_ARCHITECTURE"
    oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,OSarchitecture   
    LogFile.WriteLine(Now & " - OS Architecture: " & OSarchitecture )           
End Function

'Functions
'---------------------------------------------------------------------------------------------------------------------
Function Results(KBname)  
    Select Case Return      
        Case 9009              
        LogFile.WriteLine(Now & "  -  WARNING: " & KBname & " is already installed; skipping installation.")              
        Case 2359302                  
        LogFile.WriteLine(Now & "  -  WARNING: " & KBname & " is already installed; skipping installation.")              
        Case -2145124329                  
        LogFile.WriteLine(Now & "  -  WARNING: " & KBname & " is not required for this system; skipping installation.")              
        Case Else                  
        LogFile.WriteLine(Now & "  -  Install of " & KBname & " has completed with return code: " & RETURN)          
    End Select   
End Function

Function logFolder
    'Set objFSO = CreateObject("Scripting.FileSystemObject")   
    If objFSO.FolderExists("C:\ProgramData\IE11") Then
        Set objFolder = objFSO.GetFolder("C:\ProgramData\IE11")
    Else
        Set objFolder = objFSO.CreateFolder("C:\ProgramData\IE11")
    End If
End Function

Sub Usage(bExit)
    LogFile.WriteLine(Now & " - " & kErrorSuccess )
    If bExit Then
        WScript.Quit(1)
    End If
End Sub

0 commenti:

Post a Comment

Give me you feedback!