Jump to content
Sign in to follow this  
Colyn1337

Automatic Firmware Updates - SQLite & WMI

Recommended Posts

Colyn1337

#cs -----------------------------------------------------------------------------------------------------------------
Author:
Colyn Via
Script Function:
Query local device WMI info and perform a SQL lookup to check for firmware updates. The SQL database contains
device models, current firmware version, and the path to the update package. This script looks for the firmware
version based on the device model, and then copies the installer to the host drive. The script then performs a
silent install of the firmware update all the while preventing an accidental shutdown. This script has a verbose
log which gets copied to a network location if there's a problem. If it's successful the log writes a single
line to a master log in the same network location reporting it's success. Once the update is complete, the
installer file is deleted, as well as the local log file.
Version Notes:
1.0.03 - Adjusted final write to local log so that the $FirmwareDBResult is written in the log.
1.0.02 - Added processwait() to script to prevent premature script completion
1.0.01 - Added values to BIOSString dump in addition to names
1.0.00 - Initial complete version
#ce -----------------------------------------------------------------------------------------------------------------
#NoTrayIcon
#include 
#include 
; Unless directed otherwise, autoit will do an internet lookup for the driver to use. Later in the code
; the _SQLite_Startup UDF directs the program to get the driver locally. This is why it's important to
; include the driver in the package.
FileInstall("SQLite3.dll", @ScriptDir & "", 1)
Global $FWversion, $Product, $hDB, $hQuery, $aRow, $UpgradeDBResult, $FWversionDBResult, $CheckCurrent
Global $CheckDB, $UpgradeEXE, $SQLQuery1, $SQLQuery2, $PID
Global Const $Timestamp = @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " "
Global Const $Log = "C:AMTFirmwareLog_" & @ComputerName & ".txt"
Global Const $GlobalLog = 'redactedvProFirmware ResponsesSuccessSucceeded.txt'
Global Const $FirmwareDB = 'redactedvProFirmware.db'
Global Const $GlobalResponse = 'redactedvProFirmware Responses'
; This script was designed to be verbose and log most events. This code creates the log and adds the first line.
FileWriteLine($Log, $Timestamp & "Hello! My name is " & @ComputerName & ". " & @OSVersion & " " & @OSArch & " is how I roll.")
FileWriteLine($Log, $Timestamp & "I'm running script 1.0.03.")
FWversion()
; This function runs a WMI query to get the current AMT firmware version on the device.
Func FWversion()
$objIntelME = ObjGet("winmgmts:" & "." & "rootIntel_ME")
; An error catch must be present here, as AutoIt does not mute COM errors naturally. Without this catch,
; an ugly sounding error will appear to the user. IsObj() is not enough, as it cannot handle a return.
If @error Then
FileWriteLine($Log, $Timestamp & "Intel_ME is not a valid NAMESPACE.")
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
Exit
EndIf
$colIntelME = $objIntelME.ExecQuery("SELECT * FROM ME_System")
; The "Else" of this statement reports back which devices couldn't determine their firmware version.
If IsObj($colIntelME) Then
For $objMEsystem In $colIntelME
$FWversion = $objMEsystem.fwversion
Next
Else
FileWriteLine($Log, $Timestamp & "ME_System query failed.")
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
Exit
EndIf
FileWriteLine($Log, $Timestamp & "Local host vPro firmware lookup result = " & $FWversion)
ConsoleWrite("Local host vPro firmware lookup result = " & $FWversion & @LF)
EndFunc ;==>FWversion
Product()
; This function runs a WMI query to get the current model information for the device.
Func Product()
; Since these variables are used often in general coding practice, they are Local'd instead of
; declared global. When the code finishes this function, it will drop these variables.
Local $x, $y, $prodArray, $aRefine
$objWMI = ObjGet("winmgmts:" & @ComputerName & "rootHPInstrumentedBIOS")
If @error Then
FileWriteLine($Log, $Timestamp & "rootHPInstrumentedBIOS is not a valid NAMESPACE.")
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
Exit
EndIf
$colItems = $objWMI.ExecQuery("SELECT * FROM HPBIOS_BIOSString")
; The "Else" of this block accounts for the possibility that this code might run on a non HP device.
If IsObj($colItems) Then
FileWriteLine($Log, $Timestamp & "Attempting to grab hardware info.")
For $objItems In $colItems
If $objItems.Name = "Notebook Model" Then
$Product = $objItems.Value
FileWriteLine($Log, $Timestamp & "Raw value for " & $objItems.Name & " is " & $Product)
$prodArray = StringSplit($Product, " ")
; BIOS revisions change slightly how the information is presented by WMI. Sometimes it's
; simply the Model number, other times it can be a string of words. For simplicity and
; uniformity, this code strips out just the Model number from the string. This code is
; looking for a word that starts with a number. If HP begins using Model Numbers that
; start with letters, this code will need to be reworked.
For $x = 1 To $prodArray[0]
If StringIsAlpha($prodArray[$x]) Then
Else
; As it turns out, HP in its infinite wisdom decided to, in some cases, put both
; product identifiers in the SAME CIM component value. This confuses the scrip and
; it ends up recording the wrong value. To correct for this, and as the model
; number always starts with a number (currently), I've directed the script to check
; the first character in the string it's wanting to use to see if it's a number
; IsInt means "is it an integer", which in this case, the value is not. AutoIt
; sees it as a string, so Number() is used instead.
FileWriteLine($Log, $Timestamp & "I'm considering using " & $prodArray[$x] & ".")
$aRefine = StringSplit($prodArray[$x], "")
If Number($aRefine[1]) Then
FileWriteLine($Log, $Timestamp & "It turns out that " & $prodArray[$x] & " starts with " & $aRefine[1] & _
" and must therefore be what I'm looking for. Right?")
$Product = ($prodArray[$x])
EndIf
EndIf
Next
ExitLoop
ElseIf $objItems.Name = "Product Name" Then
$Product = $objItems.Value
FileWriteLine($Log, $Timestamp & "Raw value for " & $objItems.Name & " is " & $Product)
$prodArray = StringSplit($Product, " ")
For $x = 1 To $prodArray[0]
If StringIsAlpha($prodArray[$x]) Then
Else
FileWriteLine($Log, $Timestamp & "I'm considering using " & $prodArray[$x] & ".")
$aRefine = StringSplit($prodArray[$x], "")
If Number($aRefine[1]) Then
FileWriteLine($Log, $Timestamp & "It turns out that " & $prodArray[$x] & " starts with " & $aRefine[1] & _
" and must therefore be what I'm looking for. Right?")
$Product = ($prodArray[$x])
EndIf
EndIf
Next
ExitLoop
EndIf
Next
FileWriteLine($Log, $Timestamp & "Finished attempts to grab hardware info.")
; In the event that "Notebook Model" is not the value to read, it helps to see what should be added.
; The following code runs a dump of the contents of HPBIOS_BIOSstring and copies the log to the log directory.
; Later the results of the log can be used to determine what other $objItems.Name might exist.
If $Product = "" Then
FileWriteLine($Log, $Timestamp & "Query (SELECT * FROM HPBIOS_BIOSString) SUCCEEDED! However unable to " & _
"resolve object.name of known variables on " & @ComputerName & ".")
FileWriteLine($Log, "*************** Beginning Dump of HPBIOS_BIOSstring ***************")
For $objItems In $colItems
FileWriteLine($Log, "*** " & $objItems.name & " = " & $objItems.Value)
Next
FileWriteLine($Log, "*************** Done Exporting HPBIOS_BIOSstring ***************")
Sleep(5)
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
Exit
EndIf
Else
FileWriteLine($Log, $Timestamp & "rootHPInstrumentedBIOS is not a valid NAMESPACE on " & @ComputerName & ".")
EndIf
ConsoleWrite("WMI query for Model produced " & $Product & @LF)
EndFunc ;==>Product
If $FWversion = "" Then Exit
If $Product = "" Then Exit
SQL()
; This function names the SQL queries and initializes the SQL engine.
Func SQL()
; SQL Queries
$SQLQuery1 = "SELECT " & '"' & "Update" & '"' & " FROM Lookup WHERE Product=" & '"' & $Product & '"' & ';'
$SQLQuery2 = "SELECT " & '"' & "FWVersion" & '"' & " FROM Lookup WHERE Product=" & '"' & $Product & '"' & ';'
; Check the DB and open it if the script can find it
FileWriteLine($Log, $Timestamp & "Checking to see if " & '"' & $FirmwareDB & '"' & " exists...")
If FileExists($FirmwareDB) Then
FileWriteLine($Log, $Timestamp & "Found it!")
Else
FileWriteLine($Log, $Timestamp & "I can't see it!")
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
Exit
EndIf
_SQLite_Startup("", "", 0)
_SQLite_Open($FirmwareDB)
EndFunc ;==>SQL
Eligibility()
; This function determines the devices eligibility to upgrade, and figures out where to get the update from.
Func Eligibility()
; Since these variables are used often in general coding practice, they are Local'd instead of
; declared global. When the code finishes this function, it will drop these variables.
Local $x, $y, $z, $Proceed, $diff, $exe
_SQLite_Query(-1, $SQLQuery1, $hQuery)
If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then
Else
ConsoleWrite("Query Failed")
FileWriteLine($Log, $Timestamp & $SQLQuery1 & " FAILED.")
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
_SQLite_QueryFinalize($hQuery)
_SQLite_Close()
_SQLite_Shutdown()
Exit
EndIf
$UpgradeDBResult = $aRow[0]
FileWriteLine($Log, $Timestamp & $SQLQuery1 & " SUCCEEDED.")
_SQLite_QueryFinalize($hQuery)
ConsoleWrite($UpgradeDBResult & @LF)
; Need to get just the name of the update executable for use later.
$exe = StringSplit($UpgradeDBResult, "")
$UpgradeEXE = $exe[($exe[0])]
FileWriteLine($Log, $Timestamp & "The executable needed later is " & $UpgradeEXE & ".")
; Testing purposes - Making my host appear to be a 6550b
;~ $SQLQuery2 = "SELECT " & '"' & "FWVersion" & '"' & " FROM Lookup WHERE Product=" & '"' & "6550b" & '"' & ';'
_SQLite_Query(-1, $SQLQuery2, $hQuery)
If _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK Then
Else
ConsoleWrite("Query Failed")
FileWriteLine($Log, $Timestamp & $SQLQuery2 & " FAILED.")
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
_SQLite_QueryFinalize($hQuery)
_SQLite_Close()
_SQLite_Shutdown()
Exit
EndIf
$FWversionDBResult = $aRow[0]
FileWriteLine($Log, $Timestamp & $SQLQuery2 & " SUCCEEDED.")
_SQLite_QueryFinalize($hQuery)
ConsoleWrite($FWversionDBResult & @LF)
FileWriteLine($Log, $Timestamp & "Query result was " & $FWversionDBResult)
; Be sure to close down SQL when it's not needed.
_SQLite_Close()
_SQLite_Shutdown()
; Testing purposes - Make my firmware appear older
;~ $FWversion = "6.2.0.1022"
FileWriteLine($Log, $Timestamp & "Comparing firmware versions.")
; So as not to run the risk of destroying the data, the data is copied to new
; variables before be begin to break it apart into arrays.
$CheckCurrent = StringSplit($FWversion, ".")
$CheckDB = StringSplit($FWversionDBResult, ".")
FileWriteLine($Log, $Timestamp & "Splitting firmware strings.")
; This code checks to make sure the two arrays are equal in terms of size.
; If they are not, the code will generate an error. This code also manually
; adjusts either array so that it always matches the larger of the two.
If $CheckDB[0] > $CheckCurrent[0] Then
$diff = ($CheckDB[0] - $CheckCurrent[0])
For $z = 1 To $diff
_ArrayAdd($CheckCurrent, 0)
Next
EndIf
If $CheckDB[0] < $CheckCurrent[0] Then
$diff = ($CheckCurrent[0] - $CheckDB[0])
For $z = 1 To $diff
_ArrayAdd($CheckDB, 0)
Next
EndIf
FileWriteLine($Log, $Timestamp & "Finished comparing stringsplit array sizes, continuing to determine if upgrade is needed.")
; This part is checking to see if the firmware update indicated by the SQL query
; is newer than the current version on the device. If the firmware is current or
; better, the program deletes the log file and closes.
Do
For $x = 1 To $CheckDB[0]
If $CheckDB[$x] > $CheckCurrent[$x] Then
$Proceed = "y"
ExitLoop
ElseIf $CheckDB[$x] < $CheckCurrent[$x] Then
$Proceed = "n"
ExitLoop
ElseIf $CheckDB[$x] = $CheckCurrent[$x] And $x = $CheckDB[0] Then
$Proceed = "n"
ExitLoop
EndIf
Next
Until $Proceed <> ""
If $Proceed = "n" Then
FileDelete($Log)
Exit
EndIf
FileWriteLine($Log, $Timestamp & "Finished comparing firmware versions. Proceeding to UpdateFirmware()")
EndFunc ;==>Eligibility
; $UpgradeDBResult is the path to the firmware update as retrieved by the Eligibility() function
UpdateFirmware()
; This function pulls down the update and executes it. It also writes to the $GlobalLog.
Func UpdateFirmware()
FileWriteLine($Log, $Timestamp & "Attempting to copy " & '"' & $UpgradeDBResult & '"' & " to local drive.")
If FileExists($UpgradeDBResult) Then
FileCopy($UpgradeDBResult, @HomeDrive & "")
Else
FileWriteLine($Log, $Timestamp & "FileExists() check failed. I quit!")
FileCopy($Log, $GlobalResponse)
FileDelete($Log)
Exit
EndIf
FileWriteLine($Log, $Timestamp & "Run command issued for " & @HomeDrive & "" & $UpgradeEXE)
; The -s switch is for silent install
Run(@HomeDrive & "" & $UpgradeEXE & " -s", "", @SW_HIDE)
; Prevent shutdown during firmware update process
ProcessWait($UpgradeEXE, 60)
Do
Run("shutdown /a", @SystemDir, @SW_HIDE)
Sleep(10)
$PID = ProcessExists($UpgradeEXE)
Until $PID = 0
FileWriteLine($GlobalLog, $Timestamp & @ComputerName & " launched " & $UpgradeEXE & " to achieve " & $FWversionDBResult & ".")
EndFunc ;==>UpdateFirmware
FileDelete(@HomeDrive & "" & $UpgradeEXE)
FileDelete($Log)
Exit

Edited by Colyn1337

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • jasty
      By jasty
      In every other language doing   
      dim $a[3] = [1, 2, 3] $b = $a creates a reference to a but in autoit it always makes a copy.  I didn't realize this until I have performance problems and now I'm trying to switch over to the reference behavior.  How can I change the above statement so b is a reference to a and not a full copy? 
    • leomoon
      By leomoon
      Hello,
      I'm having trouble getting information from Win32_Processor:
      https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-processor
      How does this WMI Query work? Let's say I need to query VMMonitorModeExtensions, Level, ProcessorId, and ProcessorType.
      How would this work?
      Thanks.
    • colombeen
      By colombeen
      Hi everyone, I created a function to gather bitlocker information. It can tell you whether or not a drive is protected, which encryption method is being used, ...
      I tried to cover all the details in the function description
       
      The function (and 3 "internal" functions) :
      ; #FUNCTION# ==================================================================================================================== ; Name...........: _BitlockerDriveInfo ; Description ...: Get Bitlocker information for one or multiple drives ; Syntax.........: _BitlockerDriveInfo([$sDrive[, $sComputer = @ComputerName[, $bDebug = False]]]) ; Parameters ....: $sDrive - Optional: The drive. Allowed values are: ; |"" - Get the info for all available drives ; |Letter: - Get the info for the specific drive ; $sComputer - Optional: The computer from which the info should be requested ; $bDebug - Optional: Shows the hex ReturnValue from the WMI methods if set to True ; Return values .: Success - Returns a 2D array with the following information ; |[string] Drive Letter ; |[string] Drive Label ; |[string] Volume Type ; |[bool] Initialized For Protection ; |[string] Protection Status ; |[string] Lock Status ; |[bool] Auto Unlock Enabled ; |[bool] Auto Unlock Key Stored ; |[string] Conversion Status ; |[string] Encryption Method ; |[int] Encryption Percentage ; |[string] Wiping Status ; |[int] Wiping Percentage ; |[array] Key Protectors (Or [string] "None" if the drive isn't protected) ; Failure - 0, sets @error to: ; |1 - There was an issue retrieving the COM object. @extended returns error code from ObjGet ; |2 - The specified drive in $Drive doesn't exist ; |3 - There was an issue running the WMI query ; Author ........: colombeen ; Modified.......: ; Remarks .......: Requires to be run with admin elevation. Windows Vista or newer! ; A BIG THANKS to everyone from the community who contributed! ; Related .......: ; Link ..........: ; Example .......: #include <Array.au3> ; $Header = "Drive Letter|Drive Label|Volume Type|Initialized For Protection|Protection Status|" & _ ; "Lock Status|Auto Unlock Enabled|Auto Unlock Key Stored|Conversion Status|Encryption " & _ ; "Method|Encryption Percentage|Wiping Status|Wiping Percentage|Key Protectors" ; _ArrayDisplay(_BitlockerDriveInfo(), "Bitlocker Drive Info", "", 64, Default, $Header) ; =============================================================================================================================== Func _BitlockerDriveInfo($sDrive = "", $sComputer = @ComputerName, $bDebug = False) Local $aConversionStatusMsg[7] = ["Unknown", "Fully Decrypted", "Fully Encrypted", "Encryption In Progress", "Decryption In Progress", "Encryption Paused", "Decryption Paused"] Local $aEncryptionMethodMsg[9] = ["Unknown", "None", "AES_128_WITH_DIFFUSER", "AES_256_WITH_DIFFUSER", "AES_128", "AES_256", "HARDWARE_ENCRYPTION", "XTS_AES_128", "XTS_AES_256"] Local $aKeyProtectorTypeMsg[11] = ["Unknown or other protector type", "Trusted Platform Module (TPM)", "External key", "Numerical password", "TPM And PIN", "TPM And Startup Key", "TPM And PIN And Startup Key", "Public Key", "Passphrase", "TPM Certificate", "CryptoAPI Next Generation (CNG) Protector"] Local $aLockStatusMsg[3] = ["Unknown", "Unlocked", "Locked"] Local $aProtectionStatusMsg[3] = ["Unprotected", "Protected", "Unknown"] Local $aVolumeTypeMsg[3] = ["Operating System Volume", "Fixed Data Volume", "Portable Data Volume"] Local $aWipingStatusMsg[5] = ["Unknown", "Free Space Not Wiped", "Free Space Wiped", "Free Space Wiping In Progress", "Free Space Wiping Paused"] Local $iRow = 0 Local $sRunMethod, $objWMIService, $objWMIQuery, $sDriveFilter, $iProtectionStatus, $iLockStatus, $bIsAutoUnlockEnabled, $bIsAutoUnlockKeyStored, $iConversionStatus, $iEncryptionPercentage, $iEncryptionFlags, $iWipingStatus, $iWipingPercentage, $iEncryptionMethod, $aVolumeKeyProtectorID, $aVolumeKeyProtectors, $iKeyProtectorType $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & $sComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption") If @error Then Return SetError(1, @error, 0) If $sDrive <> "" Then Local $iDriveType = _WMIPropertyValue("DriveType", "Win32_LogicalDisk", "WHERE DeviceID='" & $sDrive & "'", Default, $sComputer) If @error Or ($iDriveType <> 2 And $iDriveType <> 3) Then Return SetError(2, 0, 0) $sDriveFilter = " WHERE DriveLetter='" & $sDrive & "'" EndIf $objWMIQuery = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume" & $sDriveFilter, "WQL", 0) If Not IsObj($objWMIQuery) Then Return SetError(3, 0, 0) Local $aResult[$objWMIQuery.count][14] For $objDrive In $objWMIQuery If $bDebug Then ConsoleWrite(@CRLF & "+> " & $objDrive.DriveLetter & @CRLF) If _WMIMethodExists($objDrive, "GetConversionStatus") Then $sRunMethod = $objDrive.GetConversionStatus($iConversionStatus, $iEncryptionPercentage, $iEncryptionFlags, $iWipingStatus, $iWipingPercentage) If $bDebug Then ConsoleWrite("!> GetConversionStatus 0x" & Hex($sRunMethod) & @CRLF) Else $iConversionStatus = -1 $iWipingStatus = -1 $iEncryptionPercentage = 0 $iWipingPercentage = 0 EndIf If _WMIMethodExists($objDrive, "GetEncryptionMethod") Then $sRunMethod = $objDrive.GetEncryptionMethod($iEncryptionMethod) If $bDebug Then ConsoleWrite("!> GetEncryptionMethod 0x" & Hex($sRunMethod) & @CRLF) Else $iEncryptionMethod = 0 EndIf If _WMIMethodExists($objDrive, "GetKeyProtectors") Then $sRunMethod = $objDrive.GetKeyProtectors("0", $aVolumeKeyProtectorID) If $bDebug Then ConsoleWrite("!> GetKeyProtectors 0x" & Hex($sRunMethod) & @CRLF) Else $aVolumeKeyProtectorID = 0 EndIf If _WMIMethodExists($objDrive, "GetLockStatus") Then $sRunMethod = $objDrive.GetLockStatus($iLockStatus) If $bDebug Then ConsoleWrite("!> GetLockStatus 0x" & Hex($sRunMethod) & @CRLF) Else $iLockStatus = -1 EndIf If _WMIMethodExists($objDrive, "GetProtectionStatus") Then $sRunMethod = $objDrive.GetProtectionStatus($iProtectionStatus) If $bDebug Then ConsoleWrite("!> GetProtectionStatus 0x" & Hex($sRunMethod) & @CRLF) Else $iProtectionStatus = 2 EndIf If _WMIMethodExists($objDrive, "IsAutoUnlockEnabled") Then $sRunMethod = $objDrive.IsAutoUnlockEnabled($bIsAutoUnlockEnabled) If $bDebug Then ConsoleWrite("!> IsAutoUnlockEnabled 0x" & Hex($sRunMethod) & @CRLF) Else $bIsAutoUnlockEnabled = "Unknown" EndIf If _WMIMethodExists($objDrive, "IsAutoUnlockKeyStored") Then $sRunMethod = $objDrive.IsAutoUnlockKeyStored($bIsAutoUnlockKeyStored) If $bDebug Then ConsoleWrite("!> IsAutoUnlockKeyStored 0x" & Hex($sRunMethod) & @CRLF) Else $bIsAutoUnlockKeyStored = "Unknown" EndIf If IsArray($aVolumeKeyProtectorID) And UBound($aVolumeKeyProtectorID) > 0 Then Dim $aVolumeKeyProtectors[UBound($aVolumeKeyProtectorID)][2] For $i = 0 To UBound($aVolumeKeyProtectorID) - 1 $aVolumeKeyProtectors[$i][0] = $aVolumeKeyProtectorID[$i] If _WMIMethodExists($objDrive, "GetKeyProtectorType") Then If $objDrive.GetKeyProtectorType($aVolumeKeyProtectorID[$i], $iKeyProtectorType) = 0 Then $aVolumeKeyProtectors[$i][1]= $aKeyProtectorTypeMsg[$iKeyProtectorType] Else $aVolumeKeyProtectors[$i][1]= "Unknown" EndIf Else $aVolumeKeyProtectors[$i][1] = "Unknown" EndIf Next Else $aVolumeKeyProtectors = "None" EndIf ; DriveLetter $aResult[$iRow][0] = $objDrive.DriveLetter ; DriveLabel $aResult[$iRow][1] = _WMIPropertyValue("VolumeName", "Win32_LogicalDisk", "WHERE DeviceID='" & $objDrive.DriveLetter & "'", Default, $sComputer) ; VolumeType If _WMIPropertyExists($objDrive, "VolumeType") Then $aResult[$iRow][2] = $aVolumeTypeMsg[$objDrive.VolumeType] Else If $objDrive.DriveLetter = _WMIPropertyValue("SystemDrive", "Win32_OperatingSystem", "", Default, $sComputer) Then $aResult[$iRow][2]= $aVolumeTypeMsg[0] ElseIf _WMIPropertyValue("DriveType", "Win32_LogicalDisk", "WHERE DeviceID='" & $objDrive.DriveLetter & "'", Default, $sComputer) = 3 Then $aResult[$iRow][2]= $aVolumeTypeMsg[1] ElseIf _WMIPropertyValue("DriveType", "Win32_LogicalDisk", "WHERE DeviceID='" & $objDrive.DriveLetter & "'", Default, $sComputer) = 2 Then $aResult[$iRow][2]= $aVolumeTypeMsg[2] Else $aResult[$iRow][2]= "Unknown" EndIf EndIf ; IsVolumeInitializedForProtection If _WMIPropertyExists($objDrive, "IsVolumeInitializedForProtection") Then $aResult[$iRow][3] = $objDrive.IsVolumeInitializedForProtection Else $aResult[$iRow][3] = "Unkown" EndIf ; ProtectionStatus $aResult[$iRow][4] = $aProtectionStatusMsg[$iProtectionStatus] ; LockStatus $aResult[$iRow][5] = $aLockStatusMsg[$iLockStatus + 1] ; IsAutoUnlockEnabled $aResult[$iRow][6] = $bIsAutoUnlockEnabled ; IsAutoUnlockEnabled $aResult[$iRow][7] = $bIsAutoUnlockKeyStored ; ConversionStatus $aResult[$iRow][8] = $aConversionStatusMsg[$iConversionStatus + 1] ; EncryptionMethod $aResult[$iRow][9] = $aEncryptionMethodMsg[$iEncryptionMethod + 1] ; EncryptionPercentage $aResult[$iRow][10] = $iEncryptionPercentage ; WipingStatus $aResult[$iRow][11] = $aWipingStatusMsg[$iWipingStatus + 1] ; WipingPercentage $aResult[$iRow][12] = $iWipingPercentage ; KeyProtectors $aResult[$iRow][13] = $aVolumeKeyProtectors $iRow += 1 Next _ArraySort($aResult) Return $aResult EndFunc ;==>_BitlockerDriveInfo Func _WMIPropertyExists($Object, $Property) If Not IsObj($Object) Then Return False For $sProperty In $Object.Properties_ If $sProperty.Name = $Property Then Return True Next Return False EndFunc ;==>_WMIPropertyExists Func _WMIMethodExists($Object, $Method) If Not IsObj($Object) Then Return False For $sMethod In $Object.Methods_ If $sMethod.Name = $Method Then Return True Next Return False EndFunc ;==>_WMIMethodExists Func _WMIPropertyValue($sProperty = "", $sClass = "", $sFilter = "", $sNamespace = Default, $sComputer = @ComputerName) Local $objWMIService, $objWMIQuery If $sClass = "" Or $sProperty = "" Then Return SetError(1, 0, 0) If $sFilter <> "" Then $sFilter = " " & $sFilter If $sNamespace = Default Then $sNamespace = "\root\CIMV2" $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\" & $sComputer & $sNamespace) If @error Then Return SetError(2, @error, 0) $objWMIQuery = $objWMIService.ExecQuery("SELECT * FROM " & $sClass & $sFilter, "WQL", 0x30) If Not IsObj($objWMIQuery) Then Return SetError(3, 0, 0) For $objItem In $objWMIQuery For $Property In $objItem.Properties_ If $Property.Name = $sProperty Then Return $Property.Value EndIf Next Next Return SetError(4, 0, 0) EndFunc ;==>_WMIPropertyValue  
      Example 1:
      #RequireAdmin #include <array.au3> ; Get information on all available drives Global $test = _BitlockerDriveInfo() If @error Then ConsoleWrite("!> _BitlockerDriveInfo() error: " & @error & ". extended: " & @extended & @CRLF) ElseIf IsArray($test) Then _ArrayDisplay($test, "Bitlocker Drive Info", "", 64, Default, "Drive Letter|Drive Label|Volume Type|Initialized For Protection|Protection Status|Lock Status|Auto Unlock Enabled|Auto Unlock Key Stored|Conversion Status|Encryption Method|Encryption Percentage|Wiping Status|Wiping Percentage|Key Protectors") ; Display the Key Protectors for the first record If IsArray($test[0][13]) Then _ArrayDisplay($test[0][13]) EndIf Example 2:
      #RequireAdmin #include <array.au3> ; Get information on the C-drive of the current computer + show extra information in the console Global $test = _BitlockerDriveInfo("C:", @ComputerName, True) If @error Then ConsoleWrite("!> _BitlockerDriveInfo() error: " & @error & ". extended: " & @extended & @CRLF) ElseIf IsArray($test) Then ConsoleWrite("Bitlocker information on the " & $test[0][0] & " drive" & @CRLF) ConsoleWrite("Protection Status: " & $test[0][4] & @CRLF) EndIf  
      Screenshot for the first example:

       
      Suggestions? Bugs?
      Just let me know
       
      TODO:
      ???  
      Version 1.0:
      Initial release Version 1.1:
      Fixed: Drive Label will not work when you request the information from a remote system (currently using DriveGetLabel) Fixed: The current fix for the missing VolumeType property in some Windows versions will only work locally Added: New internal function (_WMIPropertyValue()) Version 1.2:
      Fixed: The drive exists & drive type check only worked locally when a drive was specified in $sDrive
    • colombeen
      By colombeen
      Hi guys,
      I'm trying to get some information using WMI, from the Win32_EncryptableVolume class.
      I exec my query, filter out the C-drive, but when I need more info using the objects methods, I only get 1 value back and I can't seem to retrieve the other out params that should be there.
      A very minimal version of what I'm trying to do (no error checking etc, very basic). You need to start SciTE as admin or you won't see any results in the console!
      #RequireAdmin $strComputer = @ComputerName $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\CIMV2\Security\MicrosoftVolumeEncryption") $objWMIQuery = $objWMIService.ExecQuery("SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter='C:'", "WQL", 0) For $objDrive In $objWMIQuery ConsoleWrite("> " & $objDrive.GetConversionStatus() & @CRLF) ConsoleWrite("> " & $objDrive.GetConversionStatus().ConversionStatus & @CRLF) ConsoleWrite("> " & $objDrive.GetConversionStatus().EncryptionPercentage & @CRLF) Next The result from the console is : 
      > 0 > > What I'm expecting to get back is : 
      > 0 > 0 > 0 When using powershell I get this (run as admin is required!!!) : 
      PS C:\WINDOWS\system32> (Get-WmiObject -namespace "Root\cimv2\security\MicrosoftVolumeEncryption" -ClassName "Win32_Encryptablevolume" -Filter "DriveLetter='C:'").GetConversionStatus() ... ConversionStatus : 0 EncryptionFlags : 0 EncryptionPercentage : 0 ReturnValue : 0 ... All I seem to be getting is the ReturnValue when I use the method.
      I've tried this on multiple methods, always ending up with the same result
      Anyone here who has experience with this type of thing?
       
      Greetz
      colombeen
    • rm4453
      By rm4453
      Hello,
       
      I am currently writing a program that parses a massive table from a website, and need a way to add a progress bar while parsing.
      I am currently using the function _IETableWriteToArray($oObj, True) to parse the array. I need the progress bar to update as the table is parsed, not just at the end of the parsing.
      Any help at all would be very much appreciated!
       
      *EDIT --> The array I am left with after parsing is $array[0-50000][16]
×