C# winform授权:获取cpu和硬盘的序列号,得到机器码,传给服务器端,从而生成注册码,使软件注册使用。问

2020-10-05 军事 180阅读
首先在添加引用中选中System.Management
再在开始部门:
using System.Management;
using System.Management.Instrumentation;
private void GetInfo()
{
string cpuInfo = "";//cpu序列号
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
Response.Write ("cpu序列号:"+cpuInfo.ToString ());
}
//获取硬盘ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach(ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
Response.Write ("硬盘序列号:"+HDid.ToString ());
}
//获取网卡硬件地址
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach(ManagementObject mo in moc2)
{
if((bool)mo["IPEnabled"] == true)
Response.Write("MAC address\t{0}"+mo["MacAddress"].ToString());
mo.Dispose();
}
}

在添加引用中选中System.Management
再在开始部门:
using System.Management;
using System.Management.Instrumentation;
private void GetInfo()
{
string cpuInfo = "";//cpu序列号
ManagementClass cimobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = cimobject.GetInstances();
foreach(ManagementObject mo in moc)
{
cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
Response.Write ("cpu序列号:"+cpuInfo.ToString ());
}
//获取硬盘ID
String HDid;
ManagementClass cimobject1 = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc1 = cimobject1.GetInstances();
foreach(ManagementObject mo in moc1)
{
HDid = (string)mo.Properties["Model"].Value;
Response.Write ("硬盘序列号:"+HDid.ToString ());
}
//获取网卡硬件地址
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach(ManagementObject mo in moc2)
{
if((bool)mo["IPEnabled"] == true)
Response.Write("MAC address\t{0}"+mo["MacAddress"].ToString());
mo.Dispose();
}
}
有原始数据,生成注册码的部分,按算法处理一下就行,好象这种方法挻流行。
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com