label1.Text = GetMotherBoardID();
label2.Text = GetCpuID();
label3.Text = ComputerSID;
label4.Text = UUID;
순서로 출력됩니다.
닷넷 4.6 인가 설치되어 있어야 할 겁니다. 윈10 이면 기본으로 설치되어 있을 거구요.
namespace BoardIdTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string GetMotherBoardID()
{
string mbInfo = String.Empty;
ManagementScope scope = new ManagementScope("\\\\" + Environment.MachineName + "\\root\\cimv2");
scope.Connect();
ManagementObject wmiClass = new ManagementObject(scope, new ManagementPath("Win32_BaseBoard.Tag=\"Base Board\""), new ObjectGetOptions());
foreach (PropertyData propData in wmiClass.Properties)
{
if (propData.Name == "SerialNumber")
{
//mbInfo = String.Format("{0,-25}{1}", propData.Name, Convert.ToString(propData.Value));
mbInfo = Convert.ToString(propData.Value);
break;
}
}
return mbInfo;
}
static private string GetCpuID()
{
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == "")
{
//Get only the first CPU's ID
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
}
return cpuInfo;
}
public static string ComputerSID
{
get
{
string sid = string.Empty;
string SIDKey = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
RegistryKey baseKey = null;
if (Environment.Is64BitOperatingSystem)
{
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
}
else
{
baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default);
}
RegistryKey key = baseKey.OpenSubKey(SIDKey);
object keyValue = key.GetValue("ProductId");
if (keyValue != null)
{
sid = keyValue.ToString();
}
key = null;
keyValue = null;
return sid;
}
}
public static string UUID
{
get
{
string uuid = string.Empty;
ManagementClass mc = new ManagementClass("Win32_ComputerSystemProduct");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
uuid = mo.Properties["UUID"].Value.ToString();
break;
}
return uuid;
}
}
private void Form1_Load(object sender, EventArgs e)
{
label1.Text = GetMotherBoardID();
label2.Text = GetCpuID();
label3.Text = ComputerSID;
label4.Text = UUID;
}
}