Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            DmiStructureCollection structures = DMI.CreateInstance().Structures;

            // type 0
            string biosVersion = GetSmbiosProperty(structures, DmiProperty.Bios.BiosVersion);
        }
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            DMI dmi = DMI.CreateInstance();
            DmiStructureCollection structures = dmi.Structures;
            DmiStructure           structure  = structures[Class];
            DmiClass @class = structure.Elements[0];
            IEnumerable <IPropertyKey> properties = @class.ImplementedProperties;

            var result = new List <PropertyDefinitionResult>();

            foreach (var property in properties)
            {
                result.Add(
                    new PropertyDefinitionResult
                {
                    Class              = Class,
                    ClassId            = (int)Class,
                    HexadecimalClassId = $"{(int)Class:X2}",
                    ImplementedVersion = $"{(@class.ImplementedVersion == DmiStructureVersion.Latest ? "Latest" : @class.ImplementedVersion.ToString())}",
                    PropertyKey        = property
                });
            }

            WriteObject((PropertyDefinitionResult[])result.ToArray().Clone(), true);
        }
Ejemplo n.º 3
0
        private static string GetSmbiosProperty(DmiStructureCollection structure, IPropertyKey key)
        {
            string result = null;

            result = structure.GetProperty(key).ToString();

            return(result);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            DmiStructureCollection structures = DMI.Instance.Structures;

            // type 0
            string biosVersion      = GetSmbiosProperty(structures, DmiProperty.Bios.BiosVersion);
            string biosVersionTyped = structures.GetProperty <string>(DmiProperty.Bios.BiosVersion);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            DMI dmi = DMI.CreateInstance();
            DmiStructureCollection structures  = dmi.Structures;
            DmiStructure           structure   = structures[Property.Class];
            DmiClass            element        = structure.Elements[Property.Index];
            QueryPropertyResult propertyResult = element.GetProperty(Property.PropertyKey);

            WriteObject(propertyResult.Value);
        }
Ejemplo n.º 6
0
        private static string GetSmbiosProperty(DmiStructureCollection structure, IPropertyKey key)
        {
            QueryPropertyResult queryResult = structure.GetProperty(key);

            if (!queryResult.Success)
            {
                return(null);
            }

            return(queryResult.Value.Value.ToString());
        }
        /// <summary>
        /// Process the command.
        /// </summary>
        protected override void ProcessRecord()
        {
            var result = new Collection <StructureResult>();
            DmiStructureCollection structures = DMI.CreateInstance().Structures;

            foreach (DmiStructure structure in structures)
            {
                result.Add(
                    new StructureResult
                {
                    Class              = structure.Class,
                    ClassId            = (int)structure.Class,
                    HexadecimalClassId = $"{(int)structure.Class:X2}"
                });
            }

            WriteObject((StructureResult[])result.ToArray().Clone(), true);
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Availables structures");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            DmiStructureCollection structures = DMI.Instance.Structures;

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName}");
            }

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine();
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName} structure detail");
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    DmiClassPropertiesTable elementProperties = element.Properties;
                    foreach (KeyValuePair <IPropertyKey, object> property in elementProperties)
                    {
                        object value = property.Value;

                        IPropertyKey key          = property.Key;
                        string       friendlyName = GetFriendlyName(key);
                        PropertyUnit valueUnit    = key.PropertyUnit;
                        string       unit         =
                            valueUnit == PropertyUnit.None
                                ? string.Empty
                                : valueUnit.ToString();

                        if (value == null)
                        {
                            Console.WriteLine($@" > {friendlyName} > NULL");
                            continue;
                        }

                        if (value is string)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                        else if (value is byte)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X2}h]");
                        }
                        else if (value is short)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is ushort)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is int)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is uint)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is long)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value is ulong)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                        {
                            Console.WriteLine($@" > {friendlyName} > {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                        }
                        else if (value.GetType() == typeof(DmiGroupAssociationElementCollection))
                        {
                            // prints elements
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                        {
                            Console.WriteLine($@" > {friendlyName}");
                            var collection = (ReadOnlyCollection <string>)value;
                            foreach (var entry in collection)
                            {
                                Console.WriteLine($@"   > {entry} {unit}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a single property directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            object biosVersion = structures.GetProperty(DmiProperty.Bios.BiosVersion);

            if (biosVersion != null)
            {
                Console.WriteLine($@" > BIOS Version > {biosVersion}");
            }

            string biosVendor = structures.GetProperty <string>(DmiProperty.Bios.Vendor);

            Console.WriteLine($@" > BIOS Vendor > {biosVendor}");

            int currentSpeed = structures.GetProperty <int>(DmiProperty.Processor.CurrentSpeed);

            Console.WriteLine($@" > Current Speed > {currentSpeed:N0} {DmiProperty.Processor.CurrentSpeed.PropertyUnit}");

            string processorManufacturer = structures.GetProperty <string>(DmiProperty.Processor.ProcessorManufacturer);

            Console.WriteLine($@" > Processor Manufacturer > {processorManufacturer}");

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            IDictionary <int, object> systemSlots = structures.GetProperties(DmiProperty.SystemSlots.SlotId);
            bool hasSystemSlots = systemSlots.Any();

            if (!hasSystemSlots)
            {
                Console.WriteLine($@" > There is no system slots information structure in this computer");
            }
            else
            {
                foreach (KeyValuePair <int, object> systemSlot in systemSlots)
                {
                    int element  = systemSlot.Key;
                    var property = ((IEnumerable <KeyValuePair <IPropertyKey, object> >)systemSlot.Value).FirstOrDefault();
                    Console.WriteLine($@" > System Slot ({element}) > {property.Value}");
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            DMI dmi = DMI.CreateInstance();

            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" SMBIOS");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine($@" Version > {dmi.SmbiosVersion}");

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Availables structures");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            DmiStructureCollection structures = dmi.Structures;

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName}");

                int totalStructures = structure.Elements.Count;
                if (totalStructures > 1)
                {
                    Console.WriteLine($@"     > {totalStructures} structures");
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Implemented SMBIOS Structure Version");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName}");

                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    Console.WriteLine($@"     > {element.ImplementedVersion}");
                }
            }

            foreach (DmiStructure structure in structures)
            {
                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    Console.WriteLine();
                    Console.WriteLine(element.ImplementedVersion == DmiStructureVersion.Latest
                        ? $@" ———————————————————————————————————————————————————— {element.ImplementedVersion} ——"
                        : $@" ——————————————————————————————————————————————————————— {element.ImplementedVersion} ——");
                    Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName} structure detail");
                    Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

                    IEnumerable <IPropertyKey> properties = element.ImplementedProperties;
                    foreach (var property in properties)
                    {
                        QueryPropertyResult queryResult  = element.GetProperty(property);
                        PropertyItem        propertyItem = queryResult.Result;
                        object       value        = propertyItem.Value;
                        string       friendlyName = property.GetPropertyName();
                        PropertyUnit valueUnit    = property.PropertyUnit;
                        string       unit         = valueUnit == PropertyUnit.None ? string.Empty : valueUnit.ToString();
                        if (value == null)
                        {
                            Console.WriteLine($@" > {friendlyName} > NULL");
                            continue;
                        }

                        if (value is string)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                        else if (value is byte)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X2}h]");
                        }
                        else if (value is short)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is ushort)
                        {
                            Console.WriteLine(property.Equals(DmiProperty.MemoryDevice.ConfiguredMemoryClockSpeed)
                                ? $@" > {friendlyName} > {value} {(int.Parse(dmi.SmbiosVersion) > 300 ? PropertyUnit.MTs : PropertyUnit.MHz)} [{value:X4}h]"
                                : $@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is int)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is uint)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is long)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value is ulong)
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                        {
                            Console.WriteLine($@" > {friendlyName} > {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                        }
                        else if (value is DmiGroupAssociationElementCollection)
                        {
                            // prints elements
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                        {
                            Console.WriteLine($@" > {friendlyName}");
                            var collection = (ReadOnlyCollection <string>)value;
                            foreach (var entry in collection)
                            {
                                Console.WriteLine($@"   > {entry} {unit}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($@" > {friendlyName} > {value} {unit}");
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a single property directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            QueryPropertyResult biosVersion = structures.GetProperty(DmiProperty.Bios.BiosVersion);

            if (biosVersion.Success)
            {
                Console.WriteLine($@" > BIOS Version > {biosVersion.Result.Value}");
            }

            QueryPropertyResult biosVendor = structures.GetProperty(DmiProperty.Bios.Vendor);

            if (biosVendor.Success)
            {
                Console.WriteLine($@" > BIOS Vendor > {biosVendor.Result.Value}");
            }

            QueryPropertyResult currentSpeed = structures.GetProperty(DmiProperty.Processor.CurrentSpeed);

            if (currentSpeed.Success)
            {
                Console.WriteLine($@" > Current Speed > {currentSpeed.Result.Value} {currentSpeed.Result.Key.PropertyUnit}");
            }

            QueryPropertyResult processorManufacturer = structures.GetProperty(DmiProperty.Processor.ProcessorManufacturer);

            if (processorManufacturer.Success)
            {
                Console.WriteLine($@" > Processor Manufacturer > {processorManufacturer.Result.Value}");
            }

            Console.WriteLine();
            Console.WriteLine(@" ———————————————————————————————————————————————— Collection ——");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@"   Handle result as collection");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            QueryPropertyCollectionResult systemSlotsQueryResult = structures.GetProperties(DmiProperty.SystemSlots.SlotDesignation);

            if (!systemSlotsQueryResult.Success)
            {
                Console.WriteLine($@" > Error(s)");
                Console.WriteLine($@"   {systemSlotsQueryResult.Errors.AsMessages().ToStringBuilder()}");
            }
            else
            {
                IEnumerable <PropertyItem> systemSlotsItems = systemSlotsQueryResult.Result.ToList();
                bool hasSystemSlotsItems = systemSlotsItems.Any();
                if (!hasSystemSlotsItems)
                {
                    Console.WriteLine($@" > Sorry, The '{DmiProperty.SystemSlots.SlotId}' property has not implemented on this system");
                }
                else
                {
                    int index = 0;
                    foreach (var systemSlotItem in systemSlotsItems)
                    {
                        Console.WriteLine($@" >  System Slot ({index}) > {systemSlotItem.Value}");
                        index++;
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ———————————————————————————————————————————————— Dictionary ——");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@"   Handle result as dictionary");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            var systemSlotsQueryDictionayResult = systemSlotsQueryResult.AsDictionaryResult();

            if (!systemSlotsQueryDictionayResult.Success)
            {
                Console.WriteLine($@" > Error(s)");
                Console.WriteLine($@"   {systemSlotsQueryDictionayResult.Errors.AsMessages().ToStringBuilder()}");
            }
            else
            {
                var  systemSlotsItems    = systemSlotsQueryDictionayResult.Result.ToList();
                bool hasSystemSlotsItems = systemSlotsItems.Any();
                if (!hasSystemSlotsItems)
                {
                    Console.WriteLine($@" > Sorry, The '{DmiProperty.SystemSlots.SlotId}' property has not implemented on this system");
                }
                else
                {
                    foreach (var systemSlotItemEntry in systemSlotsItems)
                    {
                        var itemIndex = systemSlotItemEntry.Key;
                        var itemValue = systemSlotItemEntry.Value;

                        Console.WriteLine($@" >  System Slot ({itemIndex}) > {itemValue.Value}");
                    }
                }
            }

            Console.ReadLine();
        }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(" Availables structures");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            DmiStructureCollection structures = DMI.Instance.Structures;

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine($@" {(int) structure.Class:D3}-{structure.Class}");
            }

            foreach (DmiStructure structure in structures)
            {
                Console.WriteLine();
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                Console.WriteLine($@" {(int)structure.Class:D3}-{structure.Class} structure detail");
                Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
                DmiClassCollection elements = structure.Elements;
                foreach (DmiClass element in elements)
                {
                    DmiClassPropertiesTable elementProperties = element.Properties;
                    foreach (KeyValuePair <PropertyKey, object> property in elementProperties)
                    {
                        object value = property.Value;

                        PropertyKey key = property.Key;
                        Enum        id  = key.PropertyId;

                        PropertyUnit valueUnit = key.PropertyUnit;
                        string       unit      =
                            valueUnit == PropertyUnit.None
                                ? string.Empty
                                : valueUnit.ToString();

                        if (value == null)
                        {
                            Console.WriteLine($@" > {id} > NULL");
                            continue;
                        }

                        if (value is string)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit}");
                        }
                        else if (value is byte)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X2}h]");
                        }
                        else if (value is short)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is ushort)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is int)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is uint)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X4}h]");
                        }
                        else if (value is long)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value is ulong)
                        {
                            Console.WriteLine($@" > {id} > {value} {unit} [{value:X8}h]");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <byte>))
                        {
                            Console.WriteLine($@" > {id} > {string.Join(", ", (ReadOnlyCollection<byte>)value)}");
                        }
                        else if (value.GetType() == typeof(ReadOnlyCollection <string>))
                        {
                            Console.WriteLine($@" > {id}");
                            var collection = (ReadOnlyCollection <string>)value;
                            foreach (var entry in collection)
                            {
                                Console.WriteLine($@"   > {entry} {unit}");
                            }
                        }
                        else
                        {
                            Console.WriteLine($@" > {id} > {value} {unit}");
                        }
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a single property directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");

            object biosVersion = structures.GetProperty(DmiProperty.Bios.BiosVersion);

            if (biosVersion != null)
            {
                Console.WriteLine($" > BIOS Version > {biosVersion}");
            }

            string biosVendor = structures.GetProperty <string>(DmiProperty.Bios.Vendor);

            Console.WriteLine($" > BIOS Vendor > {biosVendor}");

            string processorFamily = structures.GetProperty <string>(DmiProperty.Processor.Family);

            Console.WriteLine($" > Processor Family > {processorFamily}");

            string processorManufacturer = structures.GetProperty <string>(DmiProperty.Processor.ProcessorManufacturer);

            Console.WriteLine($" > Processor Manufacturer > {processorManufacturer}");

            Console.WriteLine();
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            Console.WriteLine(@" Gets a multiple properties directly");
            Console.WriteLine(@" ——————————————————————————————————————————————————————————————");
            IDictionary <int, object> systemSlots = structures.GetProperties(DmiProperty.SystemSlots.SlotId);

            foreach (KeyValuePair <int, object> systemSlot in systemSlots)
            {
                int    element  = systemSlot.Key;
                object property = systemSlot.Value;
                Console.WriteLine($" > System Slot ({element}) > {property}");
            }

            Console.ReadLine();
        }