static void Main(string[] args) { PrivelegeHelper.ObtainSystemPrivileges(); if (!EFIEnvironment.IsSupported()) { Console.WriteLine("Not in UEFI mode!"); return; } var res = EFIEnvironment.GetEntries(); bool reboot; BootEntry bootNext = null; string str; if (args.Length != 1) { Console.WriteLine("Command line usage: efiboot [<boot item name>|<boot item number>[!]]"); Console.WriteLine("Example: efiboot ubuntu!"); Console.WriteLine("Example: efiboot \"Windows Boot Manager\""); Console.WriteLine("Example: efiboot 3!"); Console.WriteLine("! will restart the system after setting the boot next parameter"); Console.WriteLine(); Console.WriteLine("------------- Available options ----------------"); foreach (var item in res) { Console.WriteLine(item.Id + ": " + item.Description + (item.IsBootNext ? " [next]" : "") + (item.IsCurrent ? " [current]" : "")); } Console.WriteLine("------------------------------------------------"); Console.WriteLine("Choose boot next record number (add ! to reboot now) or just press <ENTER> to exit:"); str = Console.ReadLine(); } else { str = args[0]; } reboot = str.EndsWith("!"); str = str.TrimEnd('!'); if (int.TryParse(str, out var idx) && idx < res.Length) { bootNext = res[idx]; } else { bootNext = res.FirstOrDefault(x => x.Description == str); } if (bootNext != null) { EFIEnvironment.SetBootNext(bootNext); Console.WriteLine("Next boot will be: " + bootNext.Description); Console.WriteLine("Reboot: " + reboot); if (reboot && !NativeMethods.ExitWindowsEx(ExitWindows.Reboot, ShutdownReason.MajorOther | ShutdownReason.MinorOther | ShutdownReason.FlagPlanned)) { Console.WriteLine("Shutdown failed"); } } else { Console.WriteLine("Entry not found!"); } }
public static void SetBootNext(BootEntry entry) { SetBootNext(entry.Id); }