I am creating a license that is specific to a machine. The license is based on the following items:
I am assuming that if 2 of the 3 match, then my license is valid. So, the can get a new network card, and the license is still valid, etc.
Is this a good approach or am I going to have issues with this not matching or changing regularly?
I'm trying to get a unique identifier for the computer so that I can validate the license.
Please let me know how this looks or if you have a better solution!
Thanks again!
** HERE IS WHAT I CAME UP WITH **
I ended up only using the VolumeSerial, CpuId, and 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;
}
Not really an answer, but a word of caution. I worked for a software company that did a similar sort of licensing mechanism and it was... brittle. Especially on laptops. Consider:
When switching between wired and wireless on a laptop, you'll have a different MAC address on each interface.
There may be advantages to changing your MAC address. eg, some cable internet providers in the states foolishly tie your MAC address to your account and one might need to plug their computer in straight to the cable modem and then clone their router's MAC if their router were to die.
If a user were to boot from a different hard drive (for example, a flash drive or a USB stick), would this change what's reported as the first drive?
And this was long before the days of commodity virtualization. Now consider that you can switch a setting and reboot your VM and have: a different amount of RAM, a different sized hard drive, a different type of virtual hard drive controller type (IDE, SCSI, perhaps multiple SCSI controller interfaces). And you can hot-swap CD/DVD devices and change NIC settings with a mouse click.
So I'm not saying "don't do this", exactly, but I will encourage you to test this mechanism on as many machines in as many environments as you can, and I will further suggest that your users will have precious little patience when they can't run the software that they've paid for.
Have you considered hardware dongles?
I've found that the MAC address isn't really worth checking nowadays. Every computer has more than one network adapter, any one of them might be an external device that may or may not be present at any given time. We rolled out a system that paid too much attention to MAC address years ago, and it ended up being a customer service disaster.
On the other hand, it's relatively rare to swap out your CPU, motherboard, bus/disk controllers, or the main hard drive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With