2018-03-12

Autoit script to install new BIOS firmware and configuration on HP

I made this autoit script to deploy new BIOS firmware and configuration. You need to download the tools from HP and generate password and configuration files.
You might want to change the registry keys in the end to suit your company better.

There are some debug-lines you can "uncomment" to read the computer model, or you can use "wmic computersystem get model" or msinfo32.exe.

;=== Script begins ===
AutoItSetOption ( "ExpandEnvStrings", 1 )

Local $ComputerModel = "HP Z240 Tower Workstation"
Local $BIOSSettingsFile = "HPZ240TWR-BIOS.conf"
Local $BIOSFirmwareFile = "N51_0167.BIN"
Local $BIOSPasswordFile = "HPZ240TWR-PWD.bin"
Local $BIOSCheckVersion = "2018.3.1.0938"
Local $SMBIOSVersion = "N51 Ver. 01.67"

; You should not need to change anything below this line except for the fake program registry keys in the end.


$extraVariables = ""
If $CMDLINE[0] = 1 Then
   $extraVariables = $CMDLINE[1]
EndIf
Local $aReturn = 0
Local $bReturn = 0

; Get Computer model
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"
$model=""

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
       $model=$objItem.Model
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_ComputerSystem" )
Endif

;Use this to get Model when updating template
;Msgbox(0,"WMI Computer Model","Computer model: '" & $model & "'")

If $model = $ComputerModel Then
RunWait('BiosConfigUtility64.exe /npwdfile:"' & $BIOSPasswordFile & '"')
$aReturn = RunWait('BiosConfigUtility64.exe /set:"' & $BIOSSettingsFile & '" /cpwdfile:"' & $BIOSPasswordFile & '"')
$bReturn = RunWait('HPBIOSUPDREC64.exe -s -f"' & $BIOSFirmwareFile & '" -p"' & $BIOSPasswordFile & '" -r')
; Debug mode
;Msgbox(0,"DEBUG","aReturn: " & $aReturn & " bReturn: " & $bReturn )
EndIf

Local $SystemBIOSVer = RegRead("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\BIOS", "BIOSVersion")
; Debug mode
;Msgbox(0,"DEBUG","aReturn: " & $aReturn & " bReturn: " & $bReturn )
;Msgbox(0,"DEBUG","SystemBiosVer: " & $SystemBIOSVer & " $SMBIOSVersion: " & $SMBIOSVersion )
If $SystemBIOSVer = $SMBIOSVersion And $aReturn = 0 Then
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\BIOS-Settings", "DisplayVersion", "REG_SZ", $BIOSCheckVersion)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\BIOS-Settings", "DisplayName", "REG_SZ", "BIOS Settings " & $ComputerModel)
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\BIOS-Settings", "Publisher", "REG_SZ", "Changeme")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\BIOS-Settings", "DisplayIcon", "REG_SZ", "C:\Windows\System32\wbem\WMIC.exe")
RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\BIOS-Settings", "UninstallString", "REG_SZ", "noremove")
EndIf

Exit ($aReturn)
;=== Script ends ===