Created
September 19, 2018 01:31
-
-
Save KunYi/1807f1c9b58723b8aba487995892419b to your computer and use it in GitHub Desktop.
C# snippets for Windows system
This file contains 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.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