//---------------------------------------------------------------------------- // // Copyright (c) Intel Corporation, 2009-2012 All Rights Reserved. // // File: BootControlFunctionality.cs // // Contents: Demonstrate the IBootControl interface. // // //---------------------------------------------------------------------------- using System; using Intel.Manageability; using Intel.Manageability.BootControl; using Intel.Manageability.Exceptions; namespace BootControlSample { class BootControlFunctionality { /// /// Prints the boot capabilities of the Intel AMT system. /// /// The Intel AMT instance public static void GetCapabilities(IAMTInstance amt) { try { BootCapabilities bootCapabilities = amt.BootControl.BootCapabilities; Console.WriteLine("Boot Capabilities:"); Console.WriteLine("BiosReflash: " + bootCapabilities.BiosReflash); Console.WriteLine("BiosSetup: " + bootCapabilities.BiosSetup); Console.WriteLine("BiosPause: " + bootCapabilities.BiosPause); Console.WriteLine("LockPowerButton: " + bootCapabilities.LockPowerButton); Console.WriteLine("LockResetButton: " + bootCapabilities.LockResetButton); Console.WriteLine("LockKeyboard: " + bootCapabilities.LockKeyboard); Console.WriteLine("LockSleepButton: " + bootCapabilities.LockSleepButton); Console.WriteLine("UserPasswordBypass: " + bootCapabilities.UserPasswordBypass); Console.WriteLine("ForceProgressEvents: " + bootCapabilities.ForceProgressEvents); Console.WriteLine("ConfigurationDataReset: " + bootCapabilities.ConfigurationDataReset); Console.WriteLine("IDER: " + bootCapabilities.IDER); Console.WriteLine("SOL: " + bootCapabilities.SOL); Console.WriteLine("SafeMode: " + bootCapabilities.SafeMode); Console.WriteLine("HardDriveBoot: " + bootCapabilities.HardDriveBoot); Console.WriteLine("CdOrDvdBoot: " + bootCapabilities.CdOrDvdBoot); Console.WriteLine("PXEBoot: " + bootCapabilities.PXEBoot); Console.WriteLine("DiagnosticsBoot: " + bootCapabilities.DiagnosticsBoot); Console.WriteLine("FirmwareVerbosityScreenBlank: " + bootCapabilities.FirmwareVerbosityScreenBlank); Console.WriteLine("FirmwareVerbosityVerbose: " + bootCapabilities.FirmwareVerbosityVerbose); Console.WriteLine("FirmwareVerbosityQuiet: " + bootCapabilities.FirmwareVerbosityQuiet); //The Enforce Secure Boot option is enabled in Intel AMT version 8.1 and above. if (CompareVersions(amt.MajorVersion + "." + amt.MinorVersion, "8.0") > 0) Console.WriteLine("BiosSecureBoot: " + bootCapabilities.BiosSecureBoot); //The Enforce Secure Erase option is enabled in Intel AMT version 11.0 and above. if (CompareVersions(amt.MajorVersion + "." + amt.MinorVersion, "11.0") >= 0) Console.WriteLine("SecureErase: " + bootCapabilities.SecureErase); } catch (ManageabilityException ex) { Console.WriteLine("Get capabilities failed"); Console.WriteLine(ex.Message); } } /// /// Prints the current boot settings of the Intel AMT system. /// /// The Intel AMT instance public static void GetCurrentSetting(IAMTInstance amt) { BootOptionsFlags bootOptions; BootSource bootSource; FirmwareVerbosityEnum FWVerbosity; try { amt.BootControl.GetCurrentSettings(out bootSource, out bootOptions, out FWVerbosity); Console.WriteLine("Current boot Options: " + bootOptions.ToString()); Console.Write("Current boot Source: " + bootSource.Source.ToString()); Console.WriteLine(". index: " + bootSource.Index.ToString()); Console.WriteLine("Current Firmware Verbosity: " + FWVerbosity.ToString()); } catch (ManageabilityException ex) { Console.WriteLine("Get current settings failed"); Console.WriteLine(ex.Message); } } /// /// Sets the next boot to boot from a CD\DVD /// /// The Intel AMT instance public static void SetNextBoot1(IAMTInstance amt) { try { BootSource bootSource = new BootSource(BootSourceEnum.CdOrDvdBoot, 1); amt.BootControl.SetNextBoot(bootSource); Console.WriteLine("Set next boot Succeed"); } catch (ManageabilityException ex) { Console.WriteLine("Set next boot failed"); Console.WriteLine(ex.Message); } } /// /// Set the next boot to use IDE-R, SOL, and boot to the BIOS according to the capabilities. /// /// The Intel AMT instance public static void SetNextBoot2(IAMTInstance amt) { BootCapabilities bootCapabilities = amt.BootControl.BootCapabilities; BootSource bootSource; if (bootCapabilities.IDER) bootSource = new BootSource(BootSourceEnum.IDERCD); else bootSource = new BootSource(BootSourceEnum.NONE); BootOptionsFlags flags = BootOptionsFlags.NONE; if (bootCapabilities.SOL) flags |= BootOptionsFlags.UseSOL; if (bootCapabilities.BiosSetup) flags |= BootOptionsFlags.BiosSetup; FirmwareVerbosityEnum FWverbosity = FirmwareVerbosityEnum.NONE; if (bootCapabilities.FirmwareVerbosityVerbose) FWverbosity = FirmwareVerbosityEnum.Verbose; try { amt.BootControl.SetNextBoot(bootSource, flags, FWverbosity); Console.WriteLine("Set next boot succeed"); } catch (ManageabilityException ex) { Console.WriteLine("Set next boot failed"); Console.WriteLine(ex.Message); } } /// /// Enforce Secure Boot for the next boot. /// The Enforce Secure Boot ability is enabled in Intel AMT version 8.1 and above. It is enabled only on a machine that was burned specially with the BiosSecureBoot option. /// /// The Intel AMT instance public static void SetNextBoot3(IAMTInstance amt) { BootCapabilities bootCapabilities = amt.BootControl.BootCapabilities; BootOptionsFlags flags = BootOptionsFlags.NONE; if(bootCapabilities.BiosSecureBoot) flags |= BootOptionsFlags.EnforceSecureBoot; try { amt.BootControl.SetNextBoot(flags); Console.WriteLine("Enforce Secure Boot for next boot succeed"); } catch (ManageabilityException ex) { Console.WriteLine("Enforce Secure Boot for next boot failed"); Console.WriteLine(ex.Message); } } /// /// Clear the boot options for the next boot. /// /// The Intel AMT instance public static void Clear(IAMTInstance amt) { try { amt.BootControl.ClearBootOptions(); Console.WriteLine("Clear boot options succeed"); } catch (ManageabilityException ex) { Console.WriteLine("Clear boot options failed"); Console.WriteLine(ex.Message); } } /// /// Compare versions of the Intel AMT instance. /// /// The version of the Intel AMT. /// The version to compare with. /// Less than zero -The current Intel AMT version is a version before version. /// Zero - The current Intel AMT version is the same version as version. /// Greater than zero - The current Intel AMT Version is a version subsequent to version. private static int CompareVersions(string amtversion, string version) { try { Version amtVersion = new Version(amtversion); Version versionToCopmare = new Version(version); return amtVersion.CompareTo(versionToCopmare); } catch (Exception e) { throw new Exception("Compare versions failed. "+e.Message); } } } }