Read/Write EFI Variables from Windows 10 shell

2

I need to write a specific set of bytes (that I have stored in a file) to a specific EFI Variable on Windows 10. I understand this is possible in C/C++ with the Get/SetFirmwareEnvironmentVariable functions, but I'd like to do this from a shell or similar and avoid having to compile a program just for this.

Is there a way of doing this from a batch or PowerShell script?

Darkhogg

Posted 2017-07-01T11:09:10.490

Reputation: 121

I thought the whole point of the UEFI partition was that, all of its contents were encrypted, and the key was required to unencrypt it, so if it didn't match, it would also be impossible for a boot virus or other malware to be added to the boot process. So, modifying anything in this partition, you are obviating the reason for the UEFI partition, unless you are also replacing the cipher in a secure way that would not allow anyone (or you to make changes) to insert malware instead. – DaaBoss – 2017-07-01T13:33:53.473

1No, the point of the ESP is to have an OS-agnostic standard defining how the system is booted and a communication method between the booting code of the MB and the OS. SecureBoot has nothing to do with it, you can disable it and you can still modify EFI variables with it. AFAIK, nothing is encrypted: The OS allows acces or not, but it's just a FAT partition. In any case, this has nothing to do with my question. – Darkhogg – 2017-07-01T16:28:25.340

What variable do you want to change? – testeaxeax – 2017-07-01T22:19:46.947

@nullterminatedstring PreviousBoot, the variable rEFInd uses to select the default. – Darkhogg – 2017-07-02T17:13:12.787

Answers

3

You could write a powershell script including some c# code, which could access the "Get/SetFirmwareEnvironmentVariable" functions, like in this one (line 133-162).

testeaxeax

Posted 2017-07-01T11:09:10.490

Reputation: 1 315

While this points me in the right direction, I can't really accept this answer: it doesn't really answer my question and it's bad quality (mostly just just a link). – Darkhogg – 2017-07-01T22:07:05.367