[python-win32] Power management functions in pywin32?

Radek Holý radekholypublic at gmail.com
Tue Aug 7 21:13:18 CEST 2012


Hello,

are somewhere in pywin32 library implemented these functions:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa373163%28v=vs.85%29.aspx
?

If not, can you please advise how to use for example function
``PowerSetActiveScheme`` via ``ctypes``? Or this is not suitable place
for this question?

I ask because this code does not work (I cannot cope with the GUID):

>>> import ctypes
>>>
>>> class GUID(ctypes.Structure):
...     _fields_ = [
...         ('Data1', ctypes.c_ulong),
...         ('Data2', ctypes.c_ushort),
...         ('Data3', ctypes.c_ushort),
...         ('Data4', ctypes.c_ubyte*8),
...     ]
...     def __str__(self):
...         return "{%08x-%04x-%04x-%s-%s}" % (
...             self.Data1,
...             self.Data2,
...             self.Data3,
...             ''.join(["%02x" % d for d in self.Data4[:2]]),
...             ''.join(["%02x" % d for d in self.Data4[2:]]),
...         )
...
>>> array = ctypes.c_ubyte*8
>>> guid = GUID(ctypes.c_ulong(2709787400), 13633, 20395, array(188,129,247,21,86,242,11,74))
>>> ctypes.windll.powrprof.PowerSetActiveScheme(None, guid)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
WindowsError: exception: access violation reading 0xA1841308


Thank you very much
-- 
Radek Holý
Czech republic


More information about the python-win32 mailing list