Created
May 27, 2019 10:08
-
-
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...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!) | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/Arefu/7aaf982103437aec92b7561947df27d0
Updated code....