正在使用的類,裡面有獲取機器碼的方法,希望對你有幫助,此類有什麼不足之處,歡迎大家指正.
由於太長,只貼出其中的一部分.
using System;
using System.Management;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using Microsoft.Win32;
namespace CHUmanager.Common
{
/// <summary>
/// register 的摘要說明。
/// 注冊軟件所用到的類
/// 作者:xtx
/// QQ:283570270 Email:
[email protected] /// </summary>
public class Register
{
#region 獲取cpu序列號 硬盤ID 網卡硬地址
/// <summary>
/// 獲取cpu序列號
/// </summary>
/// <returns> string </returns>
public string GetCpuInfo()
{
string cpuInfo = " ";
ManagementClass cimobject = new ManagementClass( "Win32_Processor ");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc)
{
cpuInfo = mo.PropertIEs[ "ProcessorId "].Value.ToString();
}
return cpuInfo.ToString();
}
/// <summary>
/// 獲取硬盤ID
/// </summary>
/// <returns> string </returns>
public string GetHDid()
{
string HDid = " ";
ManagementClass cimobject1 = new ManagementClass( "Win32_DiskDrive ");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach(ManagementObject mo in moc1)
{
HDid = (string)mo.PropertIEs[ "Model "].Value;
}
return HDid.ToString();
}