无痕客

落花无情,流水无痕……

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
我平时整理的一个生成机器码的类,大伙看看.

using System;
using System.Management;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using Microsoft.Win32;

namespace YiSheng
{
/// <summary>
/// register 的摘要说明。
/// 注册软件所用到的类
///谊生软件 Email:yisheng163*hotmail.com
/// </summary>

public class SoftKey
{
#region 获取cpu序列号 硬盘ID 网卡硬地址
/// <summary>
/// 获取cpu序列号
/// </summary>
/// <returns>string </returns>
public static 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 static 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();
}

/// <summary>
/// 获取网卡硬件地址
/// </summary>
/// <returns>string </returns>
public static string GetMoAddress()
{
string MoAddress = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{
if ((bool)mo["IPEnabled"] == true)
MoAddress = mo["MacAddress"].ToString();
mo.Dispose();
}
return MoAddress.ToString();
}
#endregion

#region 获取网卡硬地址+CPU序列号+硬盘ID字符串
/// <summary>
/// 获取网卡硬地址+CPU序列号+硬盘ID字符串
/// </summary>
/// <returns></returns>
public static string GetAll()
{
return GetMoAddress() + GetCpuInfo() + GetHDid();
}
#endregion

}
}
posted on 2009-11-14 10:40  无痕客  阅读(1512)  评论(0编辑  收藏  举报