I have a rather crude licence key for my software, which finds all of the mac addresses for a machine and encrypts them, then compares them with an encrypted value held in the registry. If the value in the registry matches any of the values that I have just found, then the software will load. I would expect that I would always get the same values for the MAC addresses, but for a few machines, that's not true. Can anyone explain why they MAC addresses aren't fixed, or how to over come this problem?
Thanks
//// GET MAC ADDRESS
String sMacAddress = String.Empty;
ManagementScope theScope = new ManagementScope("\\\\" +Environment.MachineName + "\\root\\cimv2");
DGCSLogger.log.Trace("Management scope");
StringBuilder theQueryBuilder = new StringBuilder();
theQueryBuilder.Append("SELECT MACAddress FROM Win32_NetworkAdapter");
ObjectQuery theQuery = new ObjectQuery(theQueryBuilder.ToString());
DGCSLogger.log.Trace("Creating searcher");
ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
DGCSLogger.log.Trace("Creating collection");
ManagementObjectCollection theCollectionOfResults = theSearcher.Get();
DGCSLogger.log.Trace("Got management objects");
//// GET VALUE FROM REGISTRY
String sSavedScrambled = RegistryHelper.GetCurrentUserValue(@"Software\VB and VBA Program Settings\FMPos\settings", "LicenceKey");
String sSavedLicenceKey = String.Empty;
if (sSavedScrambled != null)
sSavedLicenceKey = DGCS.Common.Password.UnScramblePassword(sSavedScrambled);
String sMacNoLicenceKey = String.Empty;
String sMacNo = String.Empty;
///// COMPARE VALUES WITH REGISTRY VALUE
foreach (ManagementObject theCurrentObject in theCollectionOfResults)
{
DGCSLogger.log.Trace("foreach object");
if (theCurrentObject["MACAddress"] != null)
{
DGCSLogger.log.Trace("foreach object: " + theCurrentObject["MACAddress"].ToString().Substring(0, 5));
String macAdd = theCurrentObject["MACAddress"].ToString();
sMacNo = DGCS.Common.Password.ScrambleMacNumber(theCurrentObject["MACAddress"].ToString());
sMacNoLicenceKey = DGCS.Common.Password.CreateMacNoPassword(sMacNo);
DGCSLogger.log.Trace(": " + theCurrentObject["MACAddress"].ToString().Substring(0, 5));
if (sMacNoLicenceKey.Trim() == sSavedLicenceKey.Trim())
lkCheck.HasLicenceKey = true;
}
}