Kernel32GetFirmwareEnvironmentVariable Method
Retrieves the value of the specified firmware environment variable.
Note that firmware variables are not supported on a legacy BIOS-based system.
The
GetFirmwareEnvironmentVariable(String, String, IntPtr, Int32) function will always fail on a legacy BIOS-based system,
or if Windows was installed using legacy BIOS on a system that supports both legacy BIOS and UEFI.
To identify these conditions, call the function with
a dummy firmware environment name such as an empty string ("") for the
variableName parameter,
and a dummy GUID such as "{00000000-0000-0000-0000-000000000000}" for the
vendorGuid parameter.
On a legacy BIOS-based system, or on a system that supports both legacy BIOS and UEFI where Windows was
installed using legacy BIOS, the function will fail with
ERROR_INVALID_FUNCTION
On a UEFI-based system, the function will fail with an error specific to the firmware,
such as
ERROR_NOACCESS, to indicate that the dummy GUID namespace does not exist.
Namespace: DevCase.Win32.NativeMethodsAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static int GetFirmwareEnvironmentVariable(
string variableName,
string vendorGuid,
IntPtr buffer,
int bufferSize
)
<DllImportAttribute("Kernel32.dll", CharSet := CharSet.Unicode, SetLastError := true>]
Public Shared Function GetFirmwareEnvironmentVariable (
variableName As String,
vendorGuid As String,
buffer As IntPtr,
bufferSize As Integer
) As Integer
Dim variableName As String
Dim vendorGuid As String
Dim buffer As IntPtr
Dim bufferSize As Integer
Dim returnValue As Integer
returnValue = Kernel32.GetFirmwareEnvironmentVariable(variableName,
vendorGuid, buffer, bufferSize)
public:
[DllImportAttribute(L"Kernel32.dll", CharSet = CharSet::Unicode, SetLastError = true)]
static int GetFirmwareEnvironmentVariable(
String^ variableName,
String^ vendorGuid,
IntPtr buffer,
int bufferSize
)
[<DllImportAttribute("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)>]
static member GetFirmwareEnvironmentVariable :
variableName : string *
vendorGuid : string *
buffer : IntPtr *
bufferSize : int -> int
No code example is currently available or this language may not be supported.
- variableName String
-
The name of the firmware environment variable. The pointer must not be NULL.
- vendorGuid String
-
The GUID that represents the namespace of the firmware environment variable. The GUID must be a string in the format "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' represents a hexadecimal value.
- buffer IntPtr
-
A pointer to a buffer that receives the value of the specified firmware environment variable.
- bufferSize Int32
-
The size of the buffer, in bytes.
Int32
If the function succeeds, the return value is the number of bytes stored in the pBuffer buffer.
If the function fails, the return value is zero.
To get extended error information, call
GetLastWin32Error.