[python-win32] BCD WMI modification via pywin32 without effect

Radek Holý radekholypublic at gmail.com
Fri Jun 15 19:57:39 CEST 2012


2012/6/15 Tim Golden <mail at timgolden.me.uk>:
> On 15/06/2012 08:53, Radek Holý wrote:
>> Hello,
>>
>> I’m trying to edit the BCD (Boot Configuration Data) using WMI in Python:
>
> Hmmm. I'd love to help you, but I'd need to set up a VM first so I don't
> screw up my Boot Configuration along the way!
>
> I notice one small line in the docs for BcdIntegerElement:
>
>
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa362650%28v=vs.85%29.aspx
>
> which states:
>
> """
> The value is passed as a string because Automation does not natively
> support 64-bit integers
> """
>
> Frankly if that *were* the issue, I'd expect the Set... call to fail
> in the presence of integer but it's the only thing I can spot quickly.
>
> BTW my wmi module does some of the heavy lifting, but it would need some
> help here as the methods you're using are (unusually) returning further
> WMI objects. I don't think it'll help the issue you're experiencing but
> it might be worth a glance:
>
>  http://timgolden.me.uk/python/wmi/index.html
>
> TJG
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32



I found a small discrepancy in my previously mentioned VBS. But still
the VBS works and the Python script does not work.
Instead of this:
>>> if not objWBM.SetIntegerElement( &h25000004, 10 ) then
there should be this:
>>> if not objWBM.SetIntegerElement( &h25000004, 5 ) then


I must confess that my script uses your WMI module. In fact, it looks like this:

>>> import wmi
>>> import sys
>>> class_ = wmi.WMI(computer=".", impersonation_level="Impersonate", privileges=("Backup", "Restore"), namespace="WMI", suffix="BcdStore")
>>> success, store_com = class_.OpenStore("")
>>> if not success:
...     sys.exit(1)
>>>
>>> store = wmi._wmi_object(store_com)
>>> manager_com, success = store.OpenObject("{9dea862c-5cdd-4e70-acc1-f32b344d4795}")
>>> if not success:
...     sys.exit(1)
>>>
>>> manager = wmi._wmi_object(manager_com)
>>> success, = manager.SetIntegerElement(0x25000004, "5")
>>> if not success:
...     sys.exit(1)
>>>
>>> element_com, success = manager.GetElement(0x25000004)
>>> if not success:
...     sys.exit(1)
>>>
>>> element = wmi._wmi_object(element_com)
>>> print(element.Integer)

But because I am writing to this mail group, I rewrote it to use only
``win32com`` functions (wrapped by your module).


I read the notice about passing the value as a ``string``. I tried to
pass both ``string`` and ``integer`` and neither one worked.

BTW: The script only sets the timeout for the operating system
selection, so it should be safe.


--
Radek Holý
Czech republic


More information about the python-win32 mailing list