internal OperatingSystem(BcdObject bcdObject, string identifier)
        {
            if (bcdObject == null)
            {
                throw new ArgumentNullException("bcdObject");
            }

            this.Object      = bcdObject;
            this._Identifier = identifier;

            var bcdLibraryElementTypes = new[]
            {
                BcdLibraryElementTypes.BcdLibraryString_Description,
                BcdLibraryElementTypes.BcdLibraryString_ApplicationPath,
                BcdLibraryElementTypes.BcdLibraryString_PreferredLocale,
                BcdLibraryElementTypes.BcdLibraryDevice_ApplicationDevice
            };

            foreach (var type in bcdLibraryElementTypes)
            {
                ManagementBaseObject mboOut;
                var success = bcdObject.GetElement((uint)type, out mboOut);
                if (!success)
                {
                    throw new Exception();
                }

                switch (type)
                {
                case BcdLibraryElementTypes.BcdLibraryDevice_ApplicationDevice:
                    //var deviceElement = new BcdDeviceElement(mboOut);
                    //var storeFilePath = deviceElement.StoreFilePath;
                    //var managementPath = deviceElement.Path;
                    //var u = deviceElement.Type;

                    //var deviceData = new BcdDeviceData(deviceElement.Device);

                    ////object parent;
                    ////if (!this.TryGetProperty(device as ManagementBaseObject, "Parent", out parent))
                    ////{
                    ////    break;
                    ////}

                    ////object path;
                    ////if (!this.TryGetProperty(parent as ManagementBaseObject, "Path", out path))
                    ////{
                    ////    break;
                    ////}

                    ////this._ApplicationDevice = path.ToString();
                    //var additionalOptions = deviceData.AdditionalOptions;
                    //var deviceTypeValues = deviceData.DeviceType;
                    //var lateBoundObject = deviceData.LateBoundObject;
                    //var deviceLocateElementChildData = new BcdDeviceLocateElementChildData(lateBoundObject);
                    //var element = deviceLocateElementChildData.Element;
                    //var deviceData2 = new BcdDeviceData(deviceLocateElementChildData.Parent);

                    //var path = deviceData.Path;
                    break;

                case BcdLibraryElementTypes.BcdLibraryString_ApplicationPath:
                    this._ApplicationPath = mboOut.GetPropertyValue("String").ToString();
                    break;

                case BcdLibraryElementTypes.BcdLibraryString_Description:
                    this._Description = mboOut.GetPropertyValue("String").ToString();
                    break;

                case BcdLibraryElementTypes.BcdLibraryString_PreferredLocale:
                    this._Locale = mboOut.GetPropertyValue("String").ToString();
                    break;
                }
            }

            var bcdOSLoaderElementTypes = new[]
            {
                BcdOSLoaderElementTypes.BcdOSLoaderDevice_OSDevice,
                BcdOSLoaderElementTypes.BcdOSLoaderString_SystemRoot
            };

            foreach (var type in bcdOSLoaderElementTypes)
            {
                ManagementBaseObject mboOut;
                var success = bcdObject.GetElement((uint)type, out mboOut);
                if (!success)
                {
                    throw new Exception();
                }

                switch (type)
                {
                case BcdOSLoaderElementTypes.BcdOSLoaderString_SystemRoot:
                    this._SystemRoot = mboOut.GetPropertyValue("String").ToString();
                    break;
                    //case BcdOSLoaderElementTypes.BcdOSLoaderDevice_OSDevice:
                    //    object device;
                    //    if (!this.TryGetProperty(mboOut, "Device", out device))
                    //    {
                    //        break;
                    //    }

                    //    object parent;
                    //    if (!this.TryGetProperty(device as ManagementBaseObject, "Parent", out parent))
                    //    {
                    //        break;
                    //    }

                    //    object path;
                    //    if (!this.TryGetProperty(parent as ManagementBaseObject, "Path", out path))
                    //    {
                    //        break;
                    //    }

                    //    this._ApplicationDevice = path.ToString();
                    //    break;
                }
            }
        }
Beispiel #2
0
        public static IEnumerable <OperatingSystem> GetOperatingSystems()
        {
            OutputDebugLog("Start GetOperatingSystems");

            var managementScope = CreateManagementScope();

            // 現在の OS を取得
            var currentId = GetCurrentId();

            OutputDebugLog(string.Format("\tcurrentId - '{0}'", currentId));

            // 既定の OS を取得
            var defaultId = GetDefaultId();

            OutputDebugLog(string.Format("\tdefaultId - '{0}'", defaultId));

            // 次回の起動 OS を取得
            var resumeId = GetResumeId();

            OutputDebugLog(string.Format("\tresumeId - '{0}'", resumeId));

            OutputDebugLog("\tStart Enumerate List of Operating Systems");

            var order = 1;

            foreach (var id in GetIds())
            {
                var osObj = new BcdObject(managementScope, id, "");

                // USE A CLASS TO KEEP OS OBJECT AND NAME FOR LATER USE
                var operatingSystem = new OperatingSystem(osObj, id);

                // 順番
                operatingSystem.Order = order;
                order++;

                // 現在の OS かどうか
                operatingSystem.IsCurrent = id.Equals(currentId, StringComparison.InvariantCultureIgnoreCase);

                // 既定の OS かどうか
                operatingSystem.IsDefault = id.Equals(defaultId, StringComparison.InvariantCultureIgnoreCase);

                // 次回の起動 OS かどうか
                operatingSystem.IsNext = id.Equals(resumeId, StringComparison.InvariantCultureIgnoreCase);

                OutputDebugLog(string.Format("\t\tOrder - '{0}'", operatingSystem.Order));
                OutputDebugLog(string.Format("\t\tApplicationDevice - '{0}'", operatingSystem.ApplicationDevice));
                OutputDebugLog(string.Format("\t\tApplicationPath - '{0}'", operatingSystem.ApplicationPath));
                OutputDebugLog(string.Format("\t\tDescription - '{0}'", operatingSystem.Description));
                OutputDebugLog(string.Format("\t\tIdentifier - '{0}'", operatingSystem.Identifier));
                OutputDebugLog(string.Format("\t\tIsCurrent - '{0}'", operatingSystem.IsCurrent));
                OutputDebugLog(string.Format("\t\tIsDefault - '{0}'", operatingSystem.IsDefault));
                OutputDebugLog(string.Format("\t\tIsNext - '{0}'", operatingSystem.IsNext));
                OutputDebugLog(string.Format("\t\tLocale - '{0}'", operatingSystem.Locale));
                OutputDebugLog(string.Format("\t\tSystemRoot - '{0}'", operatingSystem.SystemRoot));

                yield return(operatingSystem);
            }

            OutputDebugLog("\tEnd Enumerate List of Operating Systems");

            OutputDebugLog("End GetOperatingSystems");
        }