private void InitReadReg() { string mc = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "MachineCode"); if (string.IsNullOrEmpty(mc)) { //this.EventLog.WriteEntry(String.Format("Cannot get MachineCode from REG"), EventLogEntryType.Information); return; } RegConfig.MachineCode = mc; string facName = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "FacName"); if (string.IsNullOrEmpty(facName)) { //this.EventLog.WriteEntry(String.Format("Cannot get FacName from REG"), // EventLogEntryType.Information); return; } RegConfig.FacName = facName; // 检查 "CDKey" 是否已经输入 string cdkey = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "CDKey"); if (string.IsNullOrEmpty(cdkey)) { //this.EventLog.WriteEntry(String.Format("Cannot get CDKey from REG"), // EventLogEntryType.Information); return; } RegConfig.Cdkey = cdkey; // 检查 "HostLink" 是否已经输入 string hostlink = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "HostLink"); if (string.IsNullOrEmpty(hostlink)) { //this.EventLog.WriteEntry(String.Format("Cannot get HostLink from REG"), // EventLogEntryType.Information); //return; hostlink = "http://*****:*****@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "InstallUserPath"); if (string.IsNullOrEmpty(userPath)) { this.EventLog.WriteEntry(String.Format("Cannot get InstallUserPath from REG"), EventLogEntryType.Error); return; } RegConfig.InstallUserPath = userPath; }
/// <summary> ///检查windows服务 ///检查注册表CDKey ///检查注册表FacName /// </summary> private void CheckSoftStatus(object sender) { // 检查 "appController" 服务状态 if (ServiceUtil.checkServiceIsValid("appController") == false) { MessageBox.Show("软件故障请重新安装"); QuitPanelByCode(sender); return; } // 检查 "CDKey" 是否已经输入 cdKey = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "CDKey"); EnterNewCDKey(ref cdKey, myWcf, ref validKeyInfo); }
private static bool EnterFacName(ref string facName) { // 检查 Factory Name 是否已经输入 facName = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "FacName"); if (string.IsNullOrEmpty(facName)) { InputFacName inputForm = new InputFacName(); inputForm.ShowDialog(); if (inputForm.enterKeyFlag == false) { MessageBox.Show("未正常输入,请重新启动程序并输入厂商名字"); return false; } facName = inputForm.FacName; if (string.IsNullOrEmpty(facName)) { MessageBox.Show("输入为空,请重新启动程序并输入厂商名字"); return false; } // FacName 合法,写注册表 if (RegUtil.CreateKeyValue(@"SOFTWARE\Wow6432Node\CamAligner", "FacName", facName) == false) { MessageBox.Show("由于系统问题无法注册软件"); return false; } } return true; }
internal static void Launch() { using (Stream stream = typeof(LaunchUtil).Assembly. GetManifestResourceStream("AppLauncher.Data.app.bin")) { // Kill the process if its still running. ProcessUtil.EndProcess(fileName); // Binary copy the exe file to %temp% fodler // Judge the %temp% folder exist, if not warning to reinsntall OS string appPath = Environment.GetEnvironmentVariable("localappdata"); if (Directory.Exists(appPath) == false) { MessageBox.Show("操作系统故障请重新安装"); return; } string exePath = appPath + "\\CamAligner\\" + fileName; // Copy bype stream to %temp%\***.exe byte[] bytes = new byte[(int)stream.Length]; stream.Read(bytes, 0, bytes.Length); if (File.Exists(exePath) == false) { File.WriteAllBytes(exePath, bytes); } ProcessStartInfo startInfo = new ProcessStartInfo(); // Read registry to get install location info string workDir = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "InstallPath"); if (string.IsNullOrEmpty(workDir)) { MessageBox.Show("软件故障请重新安装"); return; } startInfo.WorkingDirectory = workDir; startInfo.FileName = exePath; Process exep = new Process(); exep.StartInfo = startInfo; exep.Start(); exep.WaitForExit(); try { File.Delete(exePath); } catch { } } return; }
/// <summary> /// /// </summary> /// <param name="cdKey"></param> /// <param name="myWcf"></param> /// <param name="validKeyInfo"></param> /// <param name="reEnterCDKey"></param> private void EnterNewCDKey(ref string cdKey, MyWcfService myWcf, ref KeyInfo validKeyInfo, bool reEnterCDKey = false) { // KXXNR-OCMGT-SOFQO-WBJRY // ICFXR - YDZOG - LDPLB - NMODN // MachineCode // ProcessorId // "178BFBFF00600F12" // Win32_BIOS // "To be filled by O.E.M." // Win32_BaseBoard // "MB-1234567890" // join 3 part togeter and cal 8byte hash // result like 83628 string machineCode = RegUtil.GetRegValue(@"HKLM\SOFTWARE\Wow6432Node\CamAligner", "MachineCode"); if (string.IsNullOrEmpty(machineCode)) { try { machineCode = myWcf.GetMachineCode(); } catch { MessageBox.Show("计算机器码错误"); this.Close(); return; } } // CDKey 不存在 或者 需要重新输入(因为过期),重新输入 if (string.IsNullOrEmpty(cdKey) || reEnterCDKey) { InputCDKey inputForm = new InputCDKey(); inputForm.MachineCode = machineCode; inputForm.ShowDialog(); if (inputForm.enterKeyFlag == false) { return; } cdKey = inputForm.CDKey; if (string.IsNullOrEmpty(cdKey)) { MessageBox.Show("请输入CDKey"); return; } } try { validKeyInfo = myWcf.GetKeyInfo(cdKey, "hello"); if (validKeyInfo.IsValid == true && validKeyInfo.IsOnRightMachine == true) { JudgeCDKeyStillWorks(); LoadValidKeyOnPanel(); } else { MessageBox.Show("CDKey内容非法"); } } catch { MessageBox.Show("CDKey格式非法"); } if (validKeyInfo == null) { button1.Enabled = false; timer1.Enabled = false; } // CDKey 合法,写注册表 if (RegUtil.CreateKeyValue(@"SOFTWARE\Wow6432Node\CamAligner", "CDKey", cdKey) == false) { MessageBox.Show("由于系统问题无法注册软件"); return; } // Machine Code 合法,写注册表 if (RegUtil.CreateKeyValue(@"SOFTWARE\Wow6432Node\CamAligner", "MachineCode", machineCode) == false) { MessageBox.Show("机器码写入注册表失败"); return; } }