我正在创建一种仅适用于特定机器的许可证。该许可证基于以下项目:
- MAC地址
- CPU序列号
- 驱动器0的计算机卷序列号
我认为如果其中2个匹配,则我的许可证就是有效的。因此,用户可以更换网络卡,并且许可证仍然有效等。
这是一个好方法吗?还是说会出现无法匹配或者经常变化的问题?
我试图获取计算机的唯一标识符,以便验证许可证。
请告诉我您对此的看法,或者是否有更好的解决方案!
谢谢!
** 以下是我想到的方案 **
我最终只使用了VolumeSerial、CpuId和VideoControllerDescription。
public enum HardwareProfileComponents
{
ComputerModel,
VolumeSerial,
CpuId,
MemoryCapacity,
VideoControllerDescription
}
public static Dictionary<string, string> HardwareProfile()
{
var retval = new Dictionary<string, string>
{
{HardwareProfileComponents.ComputerModel.ToString(), GetComputerModel()},
{HardwareProfileComponents.VolumeSerial.ToString(), GetVolumeSerial()},
{HardwareProfileComponents.CpuId.ToString(), GetCpuId()},
{HardwareProfileComponents.MemoryCapacity.ToString(), GetMemoryAmount()},
{HardwareProfileComponents.VideoControllerDescription.ToString(), GetVideoControllerDescription()}
};
return retval;
}
private static string GetVideoControllerDescription()
{
Console.WriteLine("GetVideoControllerDescription");
var s1 = new ManagementObjectSearcher("select * from Win32_VideoController");
foreach (ManagementObject oReturn in s1.Get())
{
var desc = oReturn["AdapterRam"];
if ( desc == null) continue;
return oReturn["Description"].ToString().Trim();
}
return string.Empty;
}
private static string GetComputerModel()
{
Console.WriteLine("GetComputerModel");
var s1 = new ManagementObjectSearcher("select * from Win32_ComputerSystem");
foreach (ManagementObject oReturn in s1.Get())
{
return oReturn["Model"].ToString().Trim();
}
return string.Empty;
}
private static string GetMemoryAmount()
{
Console.WriteLine("GetMemoryAmount");
var s1 = new ManagementObjectSearcher("select * from Win32_PhysicalMemory");
foreach (ManagementObject oReturn in s1.Get())
{
return oReturn["Capacity"].ToString().Trim();
}
return string.Empty;
}
private static string GetVolumeSerial()
{
Console.WriteLine("GetVolumeSerial");
var disk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");
disk.Get();
string volumeSerial = disk["VolumeSerialNumber"].ToString();
disk.Dispose();
return volumeSerial;
}
private static string GetCpuId()
{
Console.WriteLine("GetCpuId");
var managClass = new ManagementClass("win32_processor");
var managCollec = managClass.GetInstances();
foreach (ManagementObject managObj in managCollec)
{
//Get only the first CPU's ID
return managObj.Properties["processorID"].Value.ToString();
}
return string.Empty;
}