Use this file to discover all available pages before exploring further.
UEFI firmware maintains a key-value store in non-volatile RAM (NVRAM) that persists across power cycles. Each variable is identified by a Unicode name and a vendor GUID, so different vendors or subsystems can use the same variable name without collision. Variables carry attribute flags that control whether they survive a reboot, whether they are accessible only during boot services, or whether they can be read at runtime by the operating system. FirmwareEnvironment is Unified.Firmware’s typed interface over this store.
FirmwareEnvironment is constructed with an IFirmwareBackend and a vendor GUID that scopes all variable operations to a single namespace.
// Scope to the UEFI global namespacevar env = new FirmwareEnvironment( FirmwareInterface.CurrentBackend, FirmwareVendors.GlobalVariable);// Scope to a vendor-specific namespacevar appleEnv = new FirmwareEnvironment( FirmwareInterface.CurrentBackend, FirmwareVendors.AppleVendor);
The two key properties exposed on every instance are:
Property
Type
Description
Backend
IFirmwareBackend
The platform backend used for all reads and writes
VendorGuid
Guid
The GUID namespace all variable operations are scoped to
T ReadVariable<T>(string varName, out VariableAttributes attributes) where T : struct;void WriteVariable<T>(string varName, T value, VariableAttributes attributes) where T : struct;
// Read the firmware's boot manager timeout (in seconds)ushort timeout = env.ReadVariable<ushort>( "Timeout", out VariableAttributes attrs);Console.WriteLine($"Boot timeout: {timeout}s (attrs: {attrs})");// Shorten the timeout and write it backenv.WriteVariable( "Timeout", (ushort)3, VariableAttributes.NON_VOLATILE | VariableAttributes.BOOTSERVICE_ACCESS | VariableAttributes.RUNTIME_ACCESS);
Read or write a contiguous array of blittable structs, such as the boot order index list.
T[] ReadArrayVariable<T>(string varName, out VariableAttributes attributes) where T : struct;void WriteArrayVariable<T>(string varName, T[] value, VariableAttributes attributes) where T : struct;
// Read the current boot orderushort[] bootOrder = env.ReadArrayVariable<ushort>( "BootOrder", out VariableAttributes attrs);Console.WriteLine("Boot order: " + string.Join(", ", bootOrder));// Reverse the order and write it backArray.Reverse(bootOrder);env.WriteArrayVariable( "BootOrder", bootOrder, VariableAttributes.NON_VOLATILE | VariableAttributes.BOOTSERVICE_ACCESS | VariableAttributes.RUNTIME_ACCESS);
GlobalFirmwareEnvironment is a subclass of FirmwareEnvironment that is pre-configured with FirmwareVendors.GlobalVariable as its namespace. It exposes the standard UEFI globally-defined variables as strongly-typed C# properties so you never have to remember variable names or marshal types by hand.Access it through the FirmwareEnvironment.Global static property, which is lazily initialised once using FirmwareInterface.CurrentBackend:
public static GlobalFirmwareEnvironment Global { get; }
// Read-only global stateConsole.WriteLine($"Booted from entry: Boot{FirmwareEnvironment.Global.BootCurrent:X4}");Console.WriteLine($"Secure Boot active: {FirmwareEnvironment.Global.SecureBoot}");Console.WriteLine($"Setup Mode: {FirmwareEnvironment.Global.SetupMode}");// Read/write global stateConsole.WriteLine($"Current timeout: {FirmwareEnvironment.Global.Timeout}s");FirmwareEnvironment.Global.Timeout = 5;// One-shot override for the next bootFirmwareEnvironment.Global.BootNext = 0x0002;
// Standard NV + BS + RT combination used for most persistent variablesvar standardAttrs = VariableAttributes.NON_VOLATILE | VariableAttributes.BOOTSERVICE_ACCESS | VariableAttributes.RUNTIME_ACCESS;
Writing to the wrong vendor GUID does not raise an error — the firmware silently creates a new variable in that namespace. If you later query it with the correct GUID you will not find your data. Always double-check the GUID before calling any write method.