Jump to content

AutoIT and BCD WMI provider


hvandrie
 Share

Go to solution Solved by hvandrie,

Recommended Posts

Hi,

I want to access the BCD (Boot Manager) store for Windows using the BCD WMI Provider.

Only, I seem to be unable to create a proper BCDStore object. I am using the following VB code(from Scripting Guys)  and am translating it to AutoIT code:

Const BcdLibraryString_Description = &h12000004
Const WindowsImages = &h10200003
Const LegacyImages = &h10300006
Const BcdLibraryDevice_ApplicationDevice = &h11000001
Const BcdLibraryDevice_ApplicationPath = &h12000002

Const BcdBootMgrDevice_BcdDevice = &h21000022
Const BcdOSLoaderDevice_OSDevice = &h21000001

strComputer = "."

Set objStoreClass = GetObject("winmgmts:{(Backup,Restore)}\\" & _
 strComputer & "\root\wmi:BcdStore")

objStoreClass.OpenStore "", objStore

Wscript.Echo "Windows images | " & WindowsImages
objStore.EnumerateObjects WindowsImages, colObjects

For Each objObject in colObjects
 objObject.GetElement BcdLibraryString_Description, objElement
 Wscript.Echo objElement.String
Next
Wscript.Echo

Executing the following code, in admin context, I can execute the GetSystemPartition method. However, the EnumerateObjects method fails....

Const $BCDWindowsImageType = 0x10200003
Const $BCDLegacyImageType = 0x10300006
Const $BCDLibString_Desc = 0x12000004

Local $WMILocator = ObjCreate("WbemScripting.SWbemLocator")
$WMILocator.Security_.Privileges.AddAsString('SeBackupPrivilege')
$WMILocator.Security_.Privileges.AddAsString('SeRestorePrivilege')
Local $WMIRootNameSpace = $WMILocator.ConnectServer(@ComputerName, "root\wmi")
Local $oStoreClass = $WMIRootNameSpace.Get("BcdStore")

Local $SystemPart = $oStoreClass.ExecMethod_('GetSystemPartition')
MsgBox($MB_ICONWARNING, "debug" , $SystemPart.Partition)

MsgBox($MB_ICONWARNING, "debug" , $BCDWindowsImageType)
;$objInParam = ""
Local $oBCDStoreObjects
$objInParam = $oStoreClass.Methods_('EnumerateObjects').InParameters.SpawnInstance_()
$objInParam.Properties_.Item('Type') = $BCDWindowsImageType
$oBCDStoreObjects = $oStoreClass.ExecMethod_('EnumerateObjects', $objInParam)
MsgBox($MB_ICONWARNING, "debug" , $oBCDStoreObjects.Properties_.Item('ReturnValue').Value)

Any help would be greatly appreciated!

Edited by hvandrie
Link to comment
Share on other sites

  • Solution

Already solved it myself.

Instead of the variable receiving the object that supposed to be returned immediately, the object had to be set to a specific property that had the object as an value.

Const $BCDWindowsImageType = 0x10200003
Const $BCDLegacyImageType = 0x10300006
Const $BCDLibString_Desc = 0x12000004
Const $BcdOSLoaderDevice_OSDevice = 0x21000001



Local $WMILocator = ObjCreate("WbemScripting.SWbemLocator")
$WMILocator.Security_.Privileges.AddAsString('SeBackupPrivilege')
$WMILocator.Security_.Privileges.AddAsString('SeRestorePrivilege')

Local $WMIRootNameSpace = $WMILocator.ConnectServer(@ComputerName, "root\wmi")
Local $oStoreClass = $WMIRootNameSpace.Get("BcdStore")

Local $objInParam = $oStoreClass.Methods_('OpenStore').InParameters.SpawnInstance_()
$objInParam.Properties_.Item('File') = ""
Local $oBCDStore = $oStoreClass.ExecMethod_('OpenStore',$objInParam).Store   ;  The Store property contains our object value

If IsObj($oBCDStore) Then

    Local $oBCDStoreObjects, $objInParam
    $objInParam = $oBCDStore.Methods_('EnumerateObjects').InParameters.SpawnInstance_()
    $objInParam.Type = $BCDWindowsImageType
    $oBCDStoreObjects = $oBCDStore.ExecMethod_('EnumerateObjects', $objInParam).Objects  ; The Objects property contains our object value 
    For $oBCDStoreObject in $oBCDStoreObjects

        MsgBox($MB_ICONWARNING, "debug", $oBCDStoreObject.Properties_.Item('Id').Value)
    Next
EndIf

I found the property containing the object value by enumerating through the object properties using the .Properties_ propertyset and display the "Name" of each property item in the set, like:

$oBCDStoreObjects = $oBCDStore.ExecMethod_('EnumerateObjects', $objInParam)

  For $oBCDStoreObject in $oBCDStoreObjects.Properties_
   MsgBox($MB_ICONWARNING, "debug", $oBCDStoreObject.Name)
  Next
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...