I'd like to read the BootOrder
UEFI variable with Python, by using the kernel32.dll
function GetFirmwareEnvironmentVariableW
. This fails:
from ctypes import *
def errcheck(result, func, args):
print(result)
print(WinError(get_last_error()))
kernel32 = WinDLL('kernel32', use_last_error=True)
GetFirmwareEnvironmentVariable = kernel32.GetFirmwareEnvironmentVariableW
GetFirmwareEnvironmentVariable.restype = c_int
GetFirmwareEnvironmentVariable.argtypes = [c_wchar_p, c_wchar_p, c_void_p, c_int]
GetFirmwareEnvironmentVariable.errcheck = errcheck
buf = " "
GetFirmwareEnvironmentVariable("BootOrder", "{8BE4DF61-93CA-11D2-AA0D-00E098032B8C}", buf, 16)
print(buf)
with:
[WinError 1] Incorrect function.
I can imagine that initializing buf
with " "
, is not the right way to do it.
How to pass a buffer pointer correctly to a WinAPI function with ctypes
?
And how to read this UEFI variable with Python?