28 September 2012

BIOS Silent Flash

This script will perform an unattended flash of the BIOS.  It will only push header (.HDR) files to the system's CMOS for the BIOS upgrade. The .HDR file will need to be extracted from BIOS upgrades. New Computer models will need to be added to the GetComputerModel() procedure, and old models removed. When adding new computers, the relative path must be placed in front of the .HDR filename. This script was written for Dell systems, but can be modified for other brands.

NOTE: Instead of using this script for dell machines, I soon learned of the hidden switches and blogged them here for all of their BIOS upgrade files. This script can still be used though for flashing the BIOS. It will have to be modified if you would like to use this script for other model machines. You will need to change the GetComputerModel procedure for the different models/brand machines.

You can download this script from here.

'*******************************************************************************   
'     Program: FlashBIOS.vbs   
'      Author: Mick Pletcher   
'        Date: 04 March 2010   
'    Modified:   
' Description: Flashes the BIOS, unattended. This script will only push header   
'              (.HDR) files to the system's CMOS for BIOS upgrade. The .HDR   
'              file will need to be extracted from BIOS upgrades. New Computer   
'              models will need to be added to the GetComputerModel()   
'              procedure, and old models removed. When adding new computers,   
'              the relative path must be placed in front of the .HDR filename.   
'              This script was written for Dell systems, but can be modified   
'              for other brands.   
'              1) Define relative installation path   
'              2) Retrieve the computer model and assign .HDR file   
'              3) Flash the BIOS if Computer Model was found   
'              4) Cleanup Global Variables   
'*******************************************************************************   

Option Explicit   

REM Define Variables   
DIM BIOSVer      : Set BIOSVer      = Nothing   
DIM Flash        : Flash            = False   
DIM RelativePath : Set RelativePath = Nothing   

REM Define the relative installation path   
DefineRelativePath()   
REM Retrieve the computer model   
GetComputerModel()   
REM Flash the BIOS if Computer Model was found   
If Flash then   
  FlashBIOS()   
End If   
REM Cleanup Global Variables   
GlobalVariableCleanup()

'*******************************************************************************   
'*******************************************************************************   

Sub DefineRelativePath()   

  REM Get File Name with full relative path   
  RelativePath = WScript.ScriptFullName   
  REM Remove file name, leaving relative path only   
  RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))   

End Sub   

'*******************************************************************************   

Sub GetComputerModel()   

  REM Define Local Varaibles   
  DIM objWMI          : Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _ 
                        & strComputer & "\root\cimv2")
  DIM colSettingsComp : Set colSettingsComp = objWMI.ExecQuery("Select * from Win32_ComputerSystem")   
  DIM CompModel       : Set CompModel   = Nothing   
  DIM objComputer     : Set objComputer = Nothing   
  DIM strComputer     : strComputer     = "."   
  

   For Each objComputer in colSettingsComp   
     CompModel = Trim(objComputer.Model)   
   Next   
   Select Case CompModel   
     Case "Latitude D410"   
       BIOSVer = RelativePath & "D410.hdr"   
       Flash = True   
     Case "Latitude D600"   
       BIOSVer = RelativePath & "D600.hdr"   
       Flash = True   
     Case "Latitude D610"   
       BIOSVer = RelativePath & "D610.hdr"   
       Flash = True   
     Case "Latitude D620"   
       BIOSVer = RelativePath & "D620.hdr"   
       Flash = True   
     Case "Latitude D630"   
       BIOSVer = RelativePath & "D630.hdr"   
       Flash = True   
     Case "Latitude D810"   
       BIOSVer = RelativePath & "D810.hdr"   
       Flash = True   
     Case "Latitude D820"   
       BIOSVer = RelativePath & "D820.hdr"   
       Flash = True   
     Case "Latitude D830"   
       BIOSVer = RelativePath & "D830.hdr"   
       Flash = True   
     Case "Latitude E6400"   
       BIOSVer = RelativePath & "E6400.hdr"   
       Flash = True   
     Case "Latitude E6500"   
       BIOSVer = RelativePath & "E6500.hdr"   
       Flash = True   
     Case "Optiplex GX270"   
       BIOSVer = RelativePath & "GX270.hdr"   
       Flash = True   
     Case "Optiplex GX280"   
       BIOSVer = RelativePath & "GX280.hdr"   
       Flash = True   
     Case "Optiplex 745"   
       BIOSVer = RelativePath & "O745.hdr"   
       Flash = True   
     Case "Optiplex 755"   
       BIOSVer = RelativePath & "O755.hdr"   
       Flash = True   
     Case "Precision M6300"   
       BIOSVer = RelativePath & "M6300.hdr"   
       Flash = True   
     Case "Precision M70"   
       BIOSVer = RelativePath & "M70.hdr"   
       Flash = True   
     Case "Precision M90"   
       BIOSVer = RelativePath & "M90.hdr"   
       Flash = True   
     Case "Precision WorkStation 360"   
       BIOSVer = RelativePath & "WS360.hdr"   
       Flash = True   
     Case "Precision WorkStation 370"   
       BIOSVer = RelativePath & "WS370.hdr"   
       Flash = True   
     Case "Precision WorkStation 380"   
       BIOSVer = RelativePath & "WS380.hdr"   
       Flash = True   
     Case "Precision WorkStation 390"   
       BIOSVer = RelativePath & "WS390.hdr"   
       Flash = True   
     Case "Precision WorkStation T3400"   
       BIOSVer = RelativePath & "T3400.hdr"   
       Flash = True   
   End Select   

   REM Cleanup Local Variables   
   Set colSettingsComp = Nothing   
   Set CompModel       = Nothing   
   Set objComputer     = Nothing   
   Set objWMI          = Nothing   
   Set strComputer     = Nothing   

 End Sub   

 '*******************************************************************************   

 Sub FlashBIOS()   

   REM Define Local Varaibles   
   Dim strComputerName : strComputerName = "."   
   Dim strNameSpace    : strNameSpace    = "root/Dellomci"
   Dim objClass        : Set objClass    = GetObject("WinMgmts:{impersonationLevel=impersonate}//" _   
                         & strComputerName & "/" & strNameSpace & ":" &
   Dim objInParam      : Set objInParam  = Nothing   
   Dim objInstance     : Set objInstance = Nothing   
   Dim objMethod       : Set objMethod   = Nothing   
   Dim ObjOutParam     : Set ObjOutParam = Nothing   
   Dim strClassName    : strClassName    = "Dell_Configuration"  
   Dim strMethod       : strMethod       = "FlashBios"
   Dim strPropValue    : strPropValue    = "Configuration"   
   DIM WinActive       : Set WinActive   = Nothing   
   DIM WshNetwork      : Set WshNetwork  = WScript.CreateObject("WScript.Network")   
   DIM WshShell        : Set WshShell    = Wscript.CreateObject("WScript.Shell")   

  
   'Retrieve the Dell_Configuration class   
    strClassName)   
   'Define task as FlashBios   
   Set objMethod = objClass.Methods_(strMethod)   
   'Set the In parameter of the method to the URL of BIOS header file   
   Set objInParam = objMethod.inParameters.SpawnInstance_()   
   objInParam.sUrl = BIOSVer   
   REM Execute the Method (Flash System)   
   Set ObjOutParam = objClass.ExecMethod_(strMethod, objInParam)   
   REM Cancel Windows Administrative Request Reboot window   
   Do   
     WinActive = WshShell.AppActivate("System Restart Notification")   
   Loop While NOT WinActive   
   WshShell.SendKeys("{TAB}")   
   Set WinActive = Nothing   
   Do   
     WinActive = WshShell.AppActivate("System Restart Notification")   
   Loop While NOT WinActive   
   WshShell.SendKeys("{ENTER}")   

   REM Local Variable Cleanup   
   Set objClass        = Nothing   
   Set objInParam      = Nothing   
   Set objInstance     = Nothing   
   Set objMethod       = Nothing   
   Set ObjOutParam     = Nothing   
   Set strClassName    = Nothing   
   Set strComputerName = Nothing   
   Set strMethod       = Nothing   
   Set strNameSpace    = Nothing   
   Set strPropValue    = Nothing   
   Set WinActive       = Nothing   
   Set WshNetwork      = Nothing   
   Set WshShell        = Nothing   

 End Sub   

 '*******************************************************************************   

 Sub GlobalVariableCleanup()   

   Set BIOSVer      = Nothing   
   Set Flash        = Nothing   
   Set RelativePath = Nothing   

 End Sub  

0 comments:

Post a Comment