/// <summary>
/// 机器码
/// </summary>
public class MachineCode
{
/// <summary>
/// 获取cpu序列号
/// </summary>
/// <returns>string </returns>
public string GetCpuInfo()
{
string cpuInfo =
using (ManagementClass cimobject = new ManagementClass( Win _Processor ))
{
ManagementObjectCollection moc = cimobject GetInstances()
foreach (ManagementObject mo in moc)
{
cpuInfo = mo Properties[ ProcessorId ] Value ToString()
mo Dispose()
孝空羡 }
}
return cpuInfo ToString()
}
/// <summary>
/// 获取硬盘ID
/// </summary>
/// <returns>string </returns>
public string GetHDid()
{
string HDid =
using (ManagementClass cimobject = new ManagementClass( Win _DiskDrive ))
亏局 {
ManagementObjectCollection moc = cimobject GetInstances()
foreach (ManagementObject mo in moc )
{
HDid = (string)mo Properties[ Model ] Value
mo Dispose()
}
}
return HDid ToString()
}
/// <summary>
/// 获取网卡巧拍硬件地址
/// </summary>
/// <returns>string </returns>
public string GetMoAddress()
{
string MoAddress =
using (ManagementClass mc = new ManagementClass( Win _NeorkAdapterConfiguration ))
{
ManagementObjectCollection moc = mc GetInstances()
foreach (ManagementObject mo in moc )
{
if ((bool)mo[ IPEnabled ] == true)
MoAddress = mo[ MacAddress ] ToString()
mo Dispose()
}
}
return MoAddress ToString()
}
lishixinzhi/Article/program/net/201311/11438所谓机器的机器码其实就是电脑的一些特征码,包括硬盘序列号、CPU编号、BIOS编号等等和硬件有关的编号。你可以用在VC++中获取这些编号,并用一定的算法将他们组合后,就生成了一个机器码,用这个机器码按照一定的算法生成一个注册码,这样就对你的软件进行了保护,使得只有拥有这个机器码的机器才能高丛安装你的软件。获取硬毁森盘序列号的方法如下(代码)以驱动器C为例:char m_Volume[256]//卷标名char m_FileSysName[256]DWORD m_SerialNum//序列号DWORD m_FileNameLengthDWORD m_FileSysFlag::GetVolumeInformation("c:\\",m_Volume,256,&m_SerialNum,&m_FileNameLength,&m_FileSysFlag,256)执行该函数后纤念亩,m_Volume就是卷标名字符串,m_SerialNum就是序列号
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)