예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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;
        }