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.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: 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
)

Parameters

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.

Return Value

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.

Remarks

See Also