Skip to content

Instantly share code, notes, and snippets.

@KunYi
Created September 19, 2018 01:31
Show Gist options
  • Save KunYi/1807f1c9b58723b8aba487995892419b to your computer and use it in GitHub Desktop.
Save KunYi/1807f1c9b58723b8aba487995892419b to your computer and use it in GitHub Desktop.
C# snippets for Windows system
using System.Management;
static void installProductKey(string key)
{
var mbs = new ManagementObjectSearcher("Select Version From SoftwareLicensingService");
foreach (ManagementObject mo in mbs.Get())
{
mo.InvokeMethod("InstallProductKey", new object[] { key });
}
}
static public string getBaseBoardManufacturer()
{
string ret = "Unknow";
try
{
var mbs = new ManagementObjectSearcher("Select Manufacturer From Win32_BaseBoard");
foreach (ManagementObject mo in mbs.Get())
{
ret = mo["Manufacturer"].ToString();
}
}
catch (Exception)
{
ret = "Unknow"; // Normally don't have SMBIOS information
}
return ret;
}
static public string getBaseBoardProduct()
{
string ret = "Unknow";
try
{
var mbs = new ManagementObjectSearcher("Select Product From Win32_BaseBoard");
foreach (ManagementObject mo in mbs.Get())
{
ret = mo["Product"].ToString();
}
}
catch (Exception)
{
ret = "Unknow"; // Normally don't have SMBIOS information
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment