GithubHelp home page GithubHelp logo

iajtin / ismbios Goto Github PK

View Code? Open in Web Editor NEW
24.0 6.0 9.0 31.8 MB

iSMBIOS is a lightweight implementation that allows us to obtain SMBIOS information. Currently only works on windows

License: MIT License

Batchfile 0.01% C# 99.99%
smbios dmi bios hardware dmtf itin smbios-information

ismbios's Introduction


What is iSMBIOS?

iSMBIOS is a lightweight implementation that allows us to obtain the SMBIOS information. Currently only works on Windows

This library implements DMTF Specification 3.7.0 version and olders versions

For more information, please see https://www.dmtf.org/standards/smbios

Install via NuGet

  • From nuget gallery
NuGet Version
  • From package manager console

PM> Install-Package iSMBIOS

Install via PowerShell

Now if you want you can use iSMBIOS from PowerShell. It has the iPowerShellSmbios module available that contains a collection of Cmdlets that allow us to obtain the SMBIOS information. If you want to know more, please review the available documentation from here.

  • From PowerShellGallery
PowerShellGallery Version
  • From PowerShell console

PM> Install-Module -Name iPowerShellSmbios

Usage

Before

Call DMI.Instance.Structures for getting all SMBIOS structures availables.

Now

The DMI.Instance property now is mark as obsolete use DMI.CreateInstance() method instead If you want to connect to a remote machine fill in an instance of the DmiConnectOptions object and use it as the argument of the DMI method.CreateInstance(optionsInstance).

For more info, please see CHANGELOG file.

Examples

  1. Gets and prints SMBIOS version.

    Console.WriteLine($@" SMBIOS Version > {DMI.CreateInstance().SmbiosVersion}");
    
  2. Gets and prints all SMBIOS availables structures.

    DmiStructureCollection structures = DMI.CreateInstance().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");
        }
    }
    
  3. Gets and prints the implemented SMBIOS structure version.

    DmiStructureCollection structures = DMI.CreateInstance().Structures;
    foreach (DmiStructure structure in structures)
    {
        Console.WriteLine($@" {(int)structure.Class:D3}-{structure.FriendlyClassName}");
    
        DmiClassCollection elements = structure.Elements;
        foreach (DmiClass element in elements)
        {
            Console.WriteLine($@"     > Version > {element.ImplementedVersion}");
        }
    }
    
  4. Gets a single property directly.

    DmiStructureCollection structures = DMI.CreateInstance().Structures;
    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}");
    }
    
  5. Gets a property in multiple elements directly (Handle result as collection).

    // Requires that the Slot Information structure exists in your system
    DmiStructureCollection structures = DMI.CreateInstance().Structures;
    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++;
            }
        }
    }
    
  6. Gets a property in multiple elements directly (Handle result as dictionary).

     // Requires that the Slot Information structure exists in your system
     DmiStructureCollection structures = DMI.CreateInstance().Structures;
     QueryPropertyCollectionResult systemSlotsQueryResult = structures.GetProperties(DmiProperty.SystemSlots.SlotDesignation);
     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}");
             }
         }
     }
    
  7. Prints all SMBIOS structures properties

     DmiStructureCollection structures = DMI.CreateInstance().Structures;      
     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}");
                 }
             }
         }
     }
    

Documentation

  • For full code documentation, please see next link documentation.

How can I send feedback!!!

If you have found iSMBIOS useful at work or in a personal project, I would love to hear about it. If you have decided not to use iSMBIOS, please send me and email stating why this is so. I will use this feedback to improve iSMBIOS in future releases.

My email address is

email.png

ismbios's People

Contributors

iajtin avatar nuklon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ismbios's Issues

nuget 1.1.0 libs identical with 1.0.9

recently when debugging an issue, I found that nuget 1.1.0 and 1.0.9 are identical.
image
--> this means the nuget 1.1.0 is actually the same as 1.0.9 in the end.
and I found that none of the libs carries version information, they are all 1.0.0.0
which will make it a bit difficult to track which version is in use when not looking in the source code.

my suggestion would be to create a build pipeline and mark the release versions during build.
any thought? @iAJTin

assembly built in debug mode.

image
I was trying to use this in a UWP app that I am working on. and Windows App Cert kit give this message about iSMBIOS assemblies are built in debug mode. is there something wrong with the build pipeline?

bug in v1.1.2

var structures = DMI.Instance.Structures;
            // type 0
    BiosVersion = GetSmbiosProperty(structures, DmiProperty.Bios.BiosVersion);

private static string GetSmbiosProperty(DmiStructureCollection structure, IPropertyKey key)
    {
        string result = null;
       
        result = structure.GetProperty(key).ToString();
            
    
        return result;
    }

the first time structure.GetProperty was called, it will throw exception....

Consider using Strong naming for the assemblies.

According to this MSDN document: https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/strong-naming

One important aspect of strong naming is that it's viral: a strong named assembly can only reference other strong named assemblies. If your library isn't strong named, then you have excluded developers who are building an application or library that needs strong naming from using it.

The benefits of strong naming are:

The assembly can be referenced and used by other strong-named assemblies.
The assembly can be stored in the Global Assembly Cache (GAC).
The assembly can be loaded side by side with other versions of the assembly. Side-by-side assembly loading is commonly required by applications with plug-in architectures.

non-strong naming assemblies can reference strong naming assemblies, but strong naming assemblies can only reference strong naming assemblies.

to allow most users to be able to use this library, I recommend use a snk file to sign the assembly projects. what needs to be done here is to create a snk file and share across the projects that are being packing into nuget package.

All other popular .net nuget packages are using this approach now.

Crashing on SMBIOS 3.1

got a system that's on SMBIOS 3.1, the program crashed when trying to get the property for Type0.

at iTin.Core.Helpers.SentinelHelper.IsTrue(Boolean expression, String message)
at iTin.Core.Helpers.SentinelHelper.IsTrue(Boolean expression)
at iTin.Core.Int32Extensions.GetByte(Int32 value, Byte onebyte)
at iTin.Core.Int32Extensions.GetByte(Int32 value, Bytes onebyte)
at iTin.Core.Hardware.Specification.Smbios.SmbiosType000.get_ExtendedBiosRomSizeUnits() in C:\iSMBIOS\src\iTin.Core.Hardware\Specification\SMBIOS\Structures\SmbiosType000 [BIOS Information].cs:line 347
at iTin.Core.Hardware.Specification.Smbios.SmbiosType000.Parse(Hashtable properties) in C:\iSMBIOS\src\iTin.Core.Hardware\Specification\SMBIOS\Structures\SmbiosType000 [BIOS Information].cs:line 550
at iTin.Core.Hardware.Specification.Smbios.SmbiosBaseType.get_Properties() in C:\iSMBIOS\src\iTin.Core.Hardware\Specification\SMBIOS\Structures\SmbiosBaseType.cs:line 84
at iTin.Core.Hardware.Specification.Dmi.DmiClass.get_Properties() in C:\iSMBIOS\src\iTin.Core.Hardware\Specification\DMI\DmiClass.cs:line 48

I checked the function, it seems the logic is throwing exception intentionally?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.