/// <summary> /// Adds the passed in (valid store) GUID to the end of the current OS entry display list for store. /// </summary> /// <param name="newGuid"></param> /// <param name="storePath"></param> /// <param name="errorDetails"></param> /// <returns></returns> public static bool AddGuidToOSDisplayList(string newGuid, string storePath, out string errorDetails) { // optional additional info on any errors encountered, sent back as output variable errorDetails = string.Empty; // default to empty string ( no errors encountered) BcdObject bcdBootMgr = new BcdObject(BcdStore_API.ImpersonationScope, Constants.GUID_WINDOWS_BOOTMGR, storePath); ManagementBaseObject mboListElements; bool successGetDisplayOrderObj = bcdBootMgr.GetElement(Constants.BCDE_BOOTMGR_TYPE_DISPLAY_ORDER, out mboListElements); if (!successGetDisplayOrderObj) { errorDetails = "Trouble getting boot manager display order object"; return(false); } else { BcdObjectListElement listElement = new BcdObjectListElement(mboListElements); string[] osDisplayList = listElement.Ids; int len = osDisplayList.Length; string[] newOsDisplayList = new string[len + 1]; for (int i = 0; i < len; i++) { newOsDisplayList[i] = osDisplayList[i]; } newOsDisplayList[len] = newGuid; //if (_updateGuidListViaObject) //{ // // this code needs research to figure out why it's not working: // //listElement.AutoCommit = true; // //listElement.Ids = newOsDisplayList; // //listElement.CommitObject(); // // DOES NOT WORK, error in WMI classes? //} //else //{ // save new display list via bcdbootmgr object's SetObjectListElement method. bool setElementStatus = bcdBootMgr.SetObjectListElement(newOsDisplayList, Constants.BCDE_BOOTMGR_TYPE_DISPLAY_ORDER); if (!setElementStatus) { errorDetails = "Trouble setting new display order list via SetObjectListElement call"; return(false); } //} } return(true); }
public void AddElement() { RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Assert.False(obj.HasElement(WellKnownElement.LibraryApplicationPath)); obj.AddElement(WellKnownElement.LibraryApplicationPath, ElementValue.ForString(@"\a\path\to\nowhere")); Assert.True(obj.HasElement(WellKnownElement.LibraryApplicationPath)); Assert.Equal(@"\a\path\to\nowhere", obj.GetElement(WellKnownElement.LibraryApplicationPath).Value.ToString()); }
public void BooleanValue() { RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Element el = obj.AddElement(WellKnownElement.LibraryAutoRecoveryEnabled, ElementValue.ForBoolean(true)); el = obj.GetElement(WellKnownElement.LibraryAutoRecoveryEnabled); Assert.Equal(true.ToString(), el.Value.ToString()); }
public void IntegerValue() { RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Element el = obj.AddElement(WellKnownElement.LibraryTruncatePhysicalMemory, ElementValue.ForInteger(1234)); el = obj.GetElement(WellKnownElement.LibraryTruncatePhysicalMemory); Assert.Equal("1234", el.Value.ToString()); }
public void IntegerListValue() { RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Element el = obj.AddElement(WellKnownElement.LibraryBadMemoryList, ElementValue.ForIntegerList(new long[] { 1234, 4132 })); el = obj.GetElement(WellKnownElement.LibraryBadMemoryList); Assert.NotNull(el.Value.ToString()); Assert.NotEmpty(el.Value.ToString()); }
public void DeviceValue_BootDevice() { RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Element el = obj.AddElement(WellKnownElement.LibraryApplicationDevice, ElementValue.ForBootDevice()); el = obj.GetElement(WellKnownElement.LibraryApplicationDevice); Assert.NotNull(el.Value.ToString()); Assert.NotEmpty(el.Value.ToString()); }
public void GuidValue() { Guid testGuid = Guid.NewGuid(); RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Element el = obj.AddElement(WellKnownElement.BootMgrDefaultObject, ElementValue.ForGuid(testGuid)); el = obj.GetElement(WellKnownElement.BootMgrDefaultObject); Assert.Equal(testGuid.ToString("B"), el.Value.ToString()); }
public void GuidListValue() { Guid testGuid1 = Guid.NewGuid(); Guid testGuid2 = Guid.NewGuid(); RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Element el = obj.AddElement(WellKnownElement.BootMgrDisplayOrder, ElementValue.ForGuidList(new Guid[] { testGuid1, testGuid2 })); el = obj.GetElement(WellKnownElement.BootMgrDisplayOrder); Assert.Equal(testGuid1.ToString("B") + "," + testGuid2.ToString("B"), el.Value.ToString()); }
public static string GetDescriptionForGuid(string guid, string storePath) { string descripFound = null; BcdObject nonEmbeddedObjRef = new BcdObject(BcdStore_API.ImpersonationScope, guid, storePath); System.Management.ManagementBaseObject Element; bool getDescripStatus = nonEmbeddedObjRef.GetElement(Constants.BCDE_LIBRARY_TYPE_DESCRIPTION, out Element); if (getDescripStatus) { descripFound = Element.GetPropertyValue("String").ToString(); } return(descripFound); }
public static List <string> GetBootManagerGUIDEntriesDisplayListAsList(string storePath) { List <string> guidList = null; BcdObject bcdObject = new BcdObject(BcdStore_API.ImpersonationScope, Constants.GUID_WINDOWS_BOOTMGR, storePath); ManagementBaseObject mboOut; bool success = bcdObject.GetElement(Constants.BCDE_BOOTMGR_TYPE_DISPLAY_ORDER, out mboOut); if (success) { string[] oSList = (string[])mboOut.GetPropertyValue("Ids"); guidList = new List <string>(); foreach (string s in oSList) { guidList.Add(s); } } return(guidList); }
public void DeviceValue_Mbr() { SparseMemoryStream ms = new SparseMemoryStream(); ms.SetLength(80 * 1024 * 1024); BiosPartitionTable pt = BiosPartitionTable.Initialize(ms, Geometry.FromCapacity(ms.Length)); pt.Create(WellKnownPartitionType.WindowsNtfs, true); VolumeManager volMgr = new VolumeManager(ms); RegistryHive hive = RegistryHive.Create(new MemoryStream()); Store s = Store.Initialize(hive.Root); BcdObject obj = s.CreateInherit(InheritType.AnyObject); Element el = obj.AddElement(WellKnownElement.LibraryApplicationDevice, ElementValue.ForDevice(Guid.Empty, volMgr.GetPhysicalVolumes()[0])); el = obj.GetElement(WellKnownElement.LibraryApplicationDevice); Assert.NotNull(el.Value.ToString()); Assert.NotEmpty(el.Value.ToString()); }
/// <summary> /// Overwrite the given bcd store's OS Display List (what displays on system load) with the given string array of guids. /// Note this is very powerful make sure you know what you are doing. /// </summary> /// <param name="arrNewGuidArray"></param> /// <param name="storePath"></param> /// <param name="errorDetails"></param> /// <returns></returns> public static bool SetOSDisplayListGuids(string[] arrNewGuidArray, string storePath, out string errorDetails) { // optional additional info on any errors encountered, sent back as output variable errorDetails = string.Empty; // default to empty string ( no errors encountered) if (arrNewGuidArray.Length == 0) { errorDetails = "This will delete ALL OS displayed list items, effectively making system boot NON-FUNCTIONAL. Disabling this functionality per this version of library..."; return(false); } BcdObject bcdBootMgr = new BcdObject(BcdStore_API.ImpersonationScope, Constants.GUID_WINDOWS_BOOTMGR, storePath); ManagementBaseObject mboListElements; bool successGetDisplayOrderObj = bcdBootMgr.GetElement(Constants.BCDE_BOOTMGR_TYPE_DISPLAY_ORDER, out mboListElements); if (!successGetDisplayOrderObj) { errorDetails = "Trouble getting boot manager display order object"; return(false); } else { BcdObjectListElement listElement = new BcdObjectListElement(mboListElements); // save new display list via bcdbootmgr object's SetObjectListElement method. bool setElementStatus = bcdBootMgr.SetObjectListElement(arrNewGuidArray, Constants.BCDE_BOOTMGR_TYPE_DISPLAY_ORDER); if (!setElementStatus) { errorDetails = "Trouble setting new display order list via SetObjectListElement call"; return(false); } } return(true); }
static bool Has(BcdObject o, uint t) { ManagementBaseObject mbo; return(o.GetElement(t, out mbo)); }
static string GetString(BcdObject o, uint t) { ManagementBaseObject mbo; return(o.GetElement(t, out mbo) ? (string)mbo.GetPropertyValue("String") : null); }
static string[] GetIds(BcdObject o, uint t) { ManagementBaseObject mbo; return(o.GetElement(t, out mbo) ? (string[])mbo.GetPropertyValue("Ids") : null); }