Skip to content

Instantly share code, notes, and snippets.

@Arefu
Created May 27, 2019 10:08
Show Gist options
  • Save Arefu/385428429c3488e5eb84cea0eeaed514 to your computer and use it in GitHub Desktop.
Save Arefu/385428429c3488e5eb84cea0eeaed514 to your computer and use it in GitHub Desktop.
¯\_(ツ)_/¯ This involves Wmi and Classes although I am not entirely sure how to describe how it works or understand why I made it but I did...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
namespace CompInfo
{
class Program
{
static void Main(string[] args)
{
var BIOSCollection = WmiSearcher.GetWmiObject("Win32_BIOS");
foreach(var BIOS in (ManagementObjectCollection)BIOSCollection) //Not the most optimal loop but it will do
{
WMI_Classes.Win32_BIOS BIOSInstance = new WMI_Classes.Win32_BIOS(BIOS);
Console.WriteLine(BIOSInstance.Name); //Show the newly set value (set with real magic!)
}
}
}
}
using System.Diagnostics;
using System.Management;
namespace CompInfo.WMI_Classes
{
class Win32_BIOS
{
//I've simplified types to keep it easy to get the point across, in an ideal situation I'd make it convert to the rigth type.
//Aside from simplification these are all the properties found within Win32_BIOS (https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-bios)
public string BiosCharacteristics;
public string BIOSVersion;
public string BuildNumber;
public string Caption;
public string CodeSet;
public string CurrentLanguage;
public string Description;
public string EmbeddedControllerMajorVersion;
public string EmbeddedControllerMinorVersion;
public string IdentificationCode;
public string InstallableLanguages;
public string InstallDate;
public string LanguageEdition;
public string ListOfLanguages;
public string Manufacturer;
public string Name;
public string OtherTargetOS;
public string PrimaryBIOS;
public string ReleaseDate;
public string SerialNumber;
public string SMBIOSBIOSVersion;
public string SMBIOSMajorVersion;
public string SMBIOSMinorVersion;
public string SMBIOSPresent;
public string SoftwareElementID;
public string SoftwareElementState;
public string Status;
public string SystemBiosMajorVersion;
public string SystemBiosMinorVersion;
public string TargetOperatingSystem;
public string Version;
public Win32_BIOS(ManagementBaseObject Instance)
{
foreach(var WmiInstanceProperty in Instance.Properties)
{
foreach(var LocalProperty in this.GetType().GetFields())
{
if(LocalProperty.Name == WmiInstanceProperty.Name) //Match up what we have in this class, to is from Win32_BIOS
{
if (WmiInstanceProperty.Value != null)
{
LocalProperty.SetValue(this, WmiInstanceProperty.Value.ToString()); //Set it in this class
}
}
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;
namespace CompInfo
{
public static class WmiSearcher
{
public static object GetWmiObject(string WmiClass)
{
return new ManagementObjectSearcher($"SELECT * FROM {WmiClass}").Get(); //YOLO Get it all
}
}
}
@Arefu
Copy link
Author

Arefu commented May 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment