private void CreateRegistry(LaunchInfo launchInfo) { if (!WindowsRegistry.IsRegeditKeyExist(Constants.EXPIRATION_DATE)) { WindowsRegistry.SetRegistryValue(Constants.EXPIRATION_DATE, launchInfo.ExpirationDate.ToShortDateString()); } if (!WindowsRegistry.IsRegeditKeyExist(Constants.ENCRYPTED_TEXT)) { WindowsRegistry.SetRegistryValue(Constants.ENCRYPTED_TEXT, launchInfo.EncryptedText); } if (!WindowsRegistry.IsRegeditKeyExist(Constants.PRODUCT_KEY)) { WindowsRegistry.SetRegistryValue(Constants.PRODUCT_KEY, launchInfo.ProductKey); } }
private bool RemoteVerifyPrdKey(string productKey) { HttpHelper http = new HttpHelper(); var postdata = string.Format("CPUSerialNumber={0}&ProductKey={1}", MachineInfo.Instance.GetCPUSerialNumber(), productKey); string responseStr = ""; if (PingHelper.Ping()) { // 验证有效性 responseStr = http.PostPage(remoteservice + "/api/device/VerifyProductKey", postdata); } var verifyKeyReponse = JsonHelper.FromJson <VerifyKeyReponse>(responseStr); if (verifyKeyReponse != null && verifyKeyReponse.ExpirationDate.HasValue) { //验证通过 var filename = Constants.PRODUCT_KEY; var launchInfo = JsonSerializeHelper.DeSerializeJson <LaunchInfo>(filename); launchInfo.ExpirationDate = verifyKeyReponse.ExpirationDate.Value.Date; launchInfo.EncryptedText = EncryptionService.EncryptText(launchInfo.ExpirationDate.ToShortDateString()); launchInfo.ProductKey = productKey; File.Delete(filename); launchInfo.SerializeJson(filename); WindowsRegistry.SetRegistryValue(Constants.EXPIRATION_DATE, launchInfo.ExpirationDate.ToShortDateString()); WindowsRegistry.SetRegistryValue(Constants.ENCRYPTED_TEXT, launchInfo.EncryptedText); WindowsRegistry.SetRegistryValue(Constants.PRODUCT_KEY, productKey); var datediff = launchInfo.ExpirationDate.Subtract(DateTime.Now).Days; return(datediff >= 0); } else { return(false); } }
public static void RunRegistryTest() { string value = string.Empty; try { WindowsRegistry.pfRegistryValue retValue; //bool regEntryExists = false; retValue = WindowsRegistry.GetRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name01", "default value is this"); _msg.Length = 0; _msg.Append("Registry read: "); _msg.Append(retValue.regValue); Program._messageLog.WriteLine(_msg.ToString()); _str.Length = 0; _str.Append("Updated Value "); _str.Append(DateTime.Now.ToString("HH_mm_ss")); retValue = WindowsRegistry.SetRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name01", (string)_str.ToString()); _msg.Length = 0; _msg.Append("Registry write: "); _msg.Append(retValue.regValue); _msg.Append(" is the value that was set."); Program._messageLog.WriteLine(_msg.ToString()); _str.Length = 0; _str.Append("Modified Value "); _str.Append(DateTime.Now.ToString("HHmmss")); retValue = WindowsRegistry.SetRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name02", (string)_str.ToString()); _msg.Length = 0; _msg.Append("Registry write: "); _msg.Append(retValue.regValue); _msg.Append(" is the value that was set."); Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Name01 "); if (WindowsRegistry.RegistryValueNameExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name01")) { _msg.Append("exists."); } else { _msg.Append("does not exist."); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Name01 for Testprog55 "); if (WindowsRegistry.RegistryValueNameExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog55", "Name01")) { _msg.Append("exists."); } else { _msg.Append("does not exist."); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Name02 "); if (WindowsRegistry.RegistryValueNameExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name02")) { _msg.Append("exists."); } else { _msg.Append("does not exist."); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Name02 Delete result: "); if (WindowsRegistry.DeleteRegistryValue("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog", "Name02")) { _msg.Append("Succeeded"); } else { _msg.Append("Failed"); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("DeleteRegistrySubKey Testprog2: "); if (WindowsRegistry.DeleteRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog2")) { _msg.Append("Succeeded"); } else { _msg.Append("Failed"); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("CreateRegistrySubKey Testprog2: "); if (WindowsRegistry.CreateRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog2")) { _msg.Append("Succeeded"); } else { _msg.Append("Failed"); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Registry SubKey Testprog2 was "); if (WindowsRegistry.RegistrySubKeyExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing\InternalApps\WinAppComponents\Testprog2")) { _msg.Append("found."); } else { _msg.Append("not found."); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("CreateRegistrySubKey: "); if (WindowsRegistry.CreateRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2")) { _msg.Append("Succeeded"); } else { _msg.Append("Failed"); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Registry SubKey was "); if (WindowsRegistry.RegistrySubKeyExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2")) { _msg.Append("found."); } else { _msg.Append("not found."); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("DeleteRegistrySubKey: "); if (WindowsRegistry.DeleteRegistrySubKey("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2")) { _msg.Append("Succeeded"); } else { _msg.Append("Failed"); } Program._messageLog.WriteLine(_msg.ToString()); _msg.Length = 0; _msg.Append("Registry SubKey was "); if (WindowsRegistry.RegistrySubKeyExists("HKEY_LOCAL_MACHINE", @"SOFTWARE\ProFastComputing2")) { _msg.Append("found."); } else { _msg.Append("not found."); } Program._messageLog.WriteLine(_msg.ToString()); } catch (System.Exception ex) { _msg.Length = 0; _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); Program._messageLog.WriteLine(_msg.ToString()); AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog); } finally { ; } } //end RunRegistryTest