Thursday, October 23, 2008

Upgrade BITS

As companies move from SMS 2003 to SCCM one of the items frequently mentioned is the desire to predeploy the latest version of BITS (Background Intelligent Transfer Service).  This makes it possible to deploy the client without requiring a reboot.  However, Microsoft didn't really provide a method for doing the BITS deployment.  So I wrote my own.  Download the latest versions of BITS from: 2000, XP, 2003, x64- XP and 2003

They will need to be in a subdirectory named bin of this script.  The script will require a drive letter to run, so when you create the program be sure to specify that option.  The nice thing about this script is that you can deploy to everybody, and it will only upgrade those that need it.

'==========================================================================
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0
'
' NAME: Install_Bits.vbs
' AUTHOR: Bill Phillips , ESRI
' DATE : 10/22/2008
'
' COMMENT:
'==========================================================================
On Error Resume Next
Dim strOSName, strSPName, strComputerType, systemroot, detectfile
Dim objFile, strFileVersion, strInstallFile


Set objShell = CreateObject ("Wscript.Shell")
set objEnv = objShell.Environment("Process")
systemroot = objEnv("SYSTEMROOT")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objExp = new regexp 'Create the RegExp object


detectOS()
detectFileversion(systemroot & "\system32\QMgr.dll")
compareBITSVersion(strFileVersion)
installBITS()

' ********************************************************************************
'Detect OS Function
'********************************************************************************
Function detectOS()
For Each objOS In GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
strOSName = objOS.Caption
strSPName = "SP" & objOS.ServicePackMajorVersion
Next

For Each objComputer In GetObject("winmgmts:").InstancesOf ("Win32_ComputerSystem")
strComputerType = objComputer.systemtype
Next

'need to normalize data (too many different versions of windows)
objExp.Pattern = "2000"
If objEXP.Test (strOSName) Then
strOSName = "win2k"
End If

objExp.Pattern = "XP"
If objEXP.Test (strOSName) Then
strOSName = "winXP"
End If

objExp.Pattern = "2003"
If objEXP.Test (strOSName) Then
strOSName = "w2k3"
End If

objExp.Pattern = "Vista"
If objEXP.Test (strOSName) Then
strOSName = "Vista"
End If

objExp.Pattern = "2008"
If objEXP.Test (strOSName) Then
strOSName = "w2k8"
End If
End Function

Function detectFileversion(detectfile)
If objFSO.FileExists(detectfile) Then
Set objFile = objFSO.GetFile(detectfile)
strFileVersion = objFSO.GetFileVersion(detectfile)
End If

End Function

Function compareBITSVersion(strFileVersion)
Select Case strFileVersion
' Case for Windows 2000 Server and Pro
Case "6.6.2600.1596"
'wscript.echo "BitsVersion Passed"
WScript.quit
WScript.Sleep 1

' Case for Windows XP SP2
'Case "6.7.2600.3143"
Case "Fake"
'wscript.echo "BitsVersion Passed"
WScript.quit
WScript.Sleep 1

' Case for Windows XP SP3
Case "6.7.2600.5512"
'wscript.echo "BitsVersion Passed"
WScript.quit
WScript.Sleep 1

' Case for Server 2003 SP1
Case "6.6.3790.1830"
'wscript.echo "BitsVersion Passed"
WScript.quit
WScript.Sleep 1

' Case for Server 2003 SP2
Case "6.6.3790.3959"
'wscript.echo "BitsVersion Passed"
WScript.quit
WScript.Sleep 1

' Case for Vista RTM
Case "7.0.6000.16386"
'wscript.echo "BitsVersion Passed"
WScript.quit
WScript.Sleep 1

' Case for Vista and Server 2008 SP1 x32 & x64
'Case "7.0.6001.18000"
Case "fake"
'wscript.echo "BitsVersion Passed"
WScript.quit
WScript.Sleep 1
' Case for failure
Case Else
'WScript.Echo "Bits Failed"
selectBITSinstall()
End Select
End Function

Function selectBITSinstall()
Select Case strComputerType
Case "x64-based PC"
Select Case strOSName
Case "w2k3"
strInstallFile = "WindowsServer2003.WindowsXP-KB923845-x64-ENU.exe"
Case "winXP"
strInstallFile = "WindowsServer2003.WindowsXP-KB923845-x64-ENU.exe"
End Select
Case "X86-based PC"
Select Case strOSName
Case "win2k"
strInstallFile = "Windows2000-KB842773-x86-ENU.exe"
Case "winXP"
strInstallFile = "WindowsXP-KB923845-x86-ENU.exe"
Case "w2k3"
strInstallFile = "WindowsServer2003-KB923845-x86-ENU.exe"
End Select
End Select

' no match found so quitting
If strInstallFile = "" Then
WScript.Quit
End If

End Function

Function installBITS()
'Turn off prompt for unknown locations
objEnv("SEE_MASK_NOZONECHECKS") = 1


objShell.Run ("bin\" & strInstallFile & " /passive /norestart /overwriteoem")', 1, True

'Turn prompt back On
objEnv.Remove("SEE_MASK_NOZONECHECKS")
End Function

No comments: