Help others and share!

The purpose of this AutoIt script is to be called at the start of a LANDESK provisioning template and validate against a list of approved devices before imaging.

TODO: Currently this script and the validation gets written to the “C” drive and was written to occur after a base image was laid down. We want to move things to “X” and call it prior to even imaging the device.

Use at your own risk and do you own testing. If you use and\or improve the script, please let me know so I can incorporate any improvements.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Fileversion=1.0.0.2
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#Region Header
;=============================================================================
;=                            Script Header                                  =
;=============================================================================
;
;    Script Purpose:
;
;    Validates that the device model has been approved for imaging. The local BIOS is queried using WMI to identify the model. The information
;        is then compared to a list of approved device models for imaging.
;
;    Pre-requisite:
;
;    This script relies on a single text file. The file contains the model number and a description seperated by a comma. One model per line.
;        Some device models (mostly Lenovo brands) will contain multiple model numbers per product line.
;
;    EX:
;        VMware Virtual Platform,This entry is for VMs
;        2325CTO,x230 Laptop
;        2320LUU,x230 Laptop
;        3438CE4,x230 Tablet
;        3438CTO,x230 Tablet
;        20AMS0EP00,x240 Laptop
;        20AMS0X900,x240 Laptop
;        20BUS19T00,T450 Laptop
;        20BUS1RY00,T450 Laptop
;        20BUS1RW00,T450 Laptop
;        20BUS19U00,T450    Laptop
;
;     The Validation file should reside at "C:\Windows\Setup\Scripts\Valid_Models_Input.txt". Use a LANDESK provisioning template file copy action to pull it in real
;        time from wherever you want to centrally store the file.
;
;
;=============================================================================
#EndRegion Header

#Region Includes & Globals
;=============================================================================
;=                         Includes & Globals                                =
;=============================================================================

#include <Constants.au3>
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>

;WMI items
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
Global $colItems1 = ""
Global $objItem1 = ""
Global $model = ""

;Validation Flags
Global $ValidModel = "No" ; yes or no can be set.
Global $WinPEMode = "No" ; yes or no can be set.

;Comparison Variables
Local $aInput
Local $BIOSInput
Global $line

;Contact Variables
Global $departmentName = "LANDESK Customer Support" ;Change to department name.
Global $departmentContact = "changeme@noaddress.com" ;Enter an email or phone number for contact

;=============================================================================
#EndRegion Includes & Globals

#Region Main
;=============================================================================
;=                               Main                                        =
;=============================================================================

;Step 1 - Make sure we are running in LANDESK WinPE Mode.
ValidateRunningWinPE()

;Step 2 - Pull BIOS info
Pull_BIOS_Information()

;Step 3 - Check for Valid Device
Validate_BIOS_Model() ; validate the model is a standard model, if not, prompt to continue anyway

Exit (0)

;=============================================================================
#EndRegion Main


#Region Local Functions
;=============================================================================
;=                               Functions                                   =
;=============================================================================
Func ValidateRunningWinPE()

    ;Simply check for the existance of a file on the X drive that would be there if running LANDESK WinPE.
    If (FileExists("X:\ldprovision\ldprovision.exe")) Then
        ;Looks like we are good.

        $WinPEMode = "yes"

    Else

        ;Files that should be there are not found. Exiting with an error code.

        $WinPEMode = "no"

        MsgBox($MB_ICONERROR, "WinPE Device Name Prompt", "This utility is intended for use with LANDESK and WinPE only. This application does not appear to be running under WinPE and will now exit.", 60)

        Exit (1)

    EndIf


EndFunc   ;==>ValidateRunningWinPE

Func Pull_BIOS_Information()

    ;Using WMI get the name from the BIOS

    ;Query WMI
    $objWMIService = ObjGet('winmgmts:\\.\root\CIMV2')
    $colItems1 = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    If IsObj($colItems1) Then
        For $objItem1 In $colItems1
            ; loop
        Next

    EndIf


    $model = $objItem1.model ; Model information from BIOS
    ;MsgBox(0,"Debug", "The BIOS indicated this model as: " & $model)    ; Debugging line leave commented out


    If $model = "" Then

        MsgBox(16, "ERROR", "The model type was not found in bios. Exiting as a failure. This message will timeout in 60 seconds.", 60) ; Test line leave remarked out
        Exit (1)

    Else
        ;For Debugging
        ;MsgBox(0, "Debug", "The BIOS reported this model as: " & $model & " This message will timeout in 60 seconds.", 60)

    EndIf

    DirCreate("X:\DeviceCheck\" & $model)


EndFunc   
;==>Pull_BIOS_Information


Func Validate_BIOS_Model()
    $InputFile = "X:\DeviceCheck\Valid_Models_Input.txt"
    _FileReadToArray($InputFile, $aInput) ; Read the list of valid models into an array
    For $i = 1 To UBound($aInput) - 1 ; Loop through array.
        $line = $aInput[$i]
        $Results = StringInStr($line, $model)
        If $Results <> 0 Then ; If $Results returns anything other then 0 it exists in the file and is valid. If the $Results returns 0 it is not found, continue to loop and is invalid.
            $ValidModel = "Yes" ; Set Valid flag to Yes.
            $i = UBound($aInput) - 1
        EndIf
    Next

    If $ValidModel = "No" Then
        $Returnvalue = MsgBox(262196, 'WARNING: Non-Standard Model Found', 'Was this intentional (Y/N)? => The model "' & $model & '" has not been prepared as a standard device, please report this to ' & $departmentName & ' at ' & $departmentContact & '.  If you select "Yes" the setup will continue but will NOT complete properly!  If you select "No", the PC will shut down.')
        Select
            Case $Returnvalue = 6 ; 6 means the name choice was intentional, allow it
                $ValidModel = "Yes"
            Case $Returnvalue = 7 ; 7 means the model is invalid, not tested and this was not intentional, don't allow it
                $ValidModel = "No"
                Shutdown(25)
                Exit (1)
        EndSelect
    EndIf
EndFunc   ;==>Validate_BIOS_Model


;=============================================================================
#EndRegion Local Functions

 

Help others and share!

One thought on “LANDESK Provisioning – Check BIOS Model Against Approval List”

  1. I have an updated script and instructions for using PRIOR to any image being laid down. The new script and instructions utilize the X drive and before any changes are made to the existing image. The update will be posted within the next 24 hours.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.