[python-win32] BCD WMI modification via pywin32 without effect
Radek Holý
radekholypublic at gmail.com
Fri Jun 15 09:53:28 CEST 2012
Hello,
I’m trying to edit the BCD (Boot Configuration Data) using WMI in Python:
>>> import sys
>>> import win32com.client
>>>
>>> def call(object, name, *args):
... method = object.Methods_(name)
... params = method.InParameters
... for param, arg in zip(params.Properties_, args):
... param.Value = arg
... result = object.ExecMethod_(name, params)
... return [param.Value for param in result.Properties_]
...
>>> objBCD = win32com.client.GetObject("winmgmts:{impersonationlevel=Impersonate,(Backup,Restore)}!root/wmi:BcdStore")
>>> success, objBcdStore = call(objBCD, "OpenStore", "")
>>> if not success:
... sys.exit(1)
...
>>> del objBCD
>>> objWBM, success = call(objBcdStore, "OpenObject", "{9dea862c-5cdd-4e70-acc1-f32b344d4795}")
>>> if not success:
... sys.exit(1)
...
>>> success, = call(objWBM, "SetIntegerElement", 0x25000004, 5)
>>> if not success:
... sys.exit(1)
...
>>> objElement, success = call(objWBM, "GetElement", 0x25000004)
>>> if not success:
... sys.exit(1)
...
>>> print(objElement.Properties_("Integer").Value)
This code has no effect (it does not change the value of element
"0x25000004"), although the equivalent in VB works as expected:
>>> dim objBCD
>>> dim objBCDStore
>>> dim objWBM
>>> dim objElement
>>>
>>> set objBCD = GetObject("winmgmts:{impersonationlevel=Impersonate,(Backup,Restore)}!root/wmi:BcdStore")
>>>
>>> if Err.number <> 0 then
... WScript.Quit(1)
... end if
>>>
>>> if not objBCD.OpenStore( "", objBcdStore ) then
... WScript.Quit(1)
... end if
>>>
>>> set objBCD = nothing
>>>
>>> if not objBcdStore.OpenObject( "{9dea862c-5cdd-4e70-acc1-f32b344d4795}", objWBM ) then
... WScript.Quit(1)
... end if
>>>
>>> if not objWBM.SetIntegerElement( &h25000004, 10 ) then
... WScript.Quit(1)
... end if
>>>
>>> if not objWBM.GetElement( &h25000004, objElement ) then
... WScript.Quit(1)
... end if
>>>
>>> WScript.Echo objElement.Integer
I execute both scripts from elevated command line.
Can you please help?
Thank you
--
Radek Holý
Czech republic
More information about the python-win32
mailing list