Ejemplo n.º 1
0
        private void OnStart(object sender, System.EventArgs e)
        {
            SettingSaver.Save(Controls);
            Settings.LoadSettings();
            string path = RegUtil.GetValue(Registry.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\OUTLOOK.EXE", "") as string;

            if (path == null)
            {
                path = "Outlook.exe";
            }

            _process = new Process();
            _process.StartInfo.FileName = path;
            if (Settings.ProcessWindowStyle == "Hidden")
            {
                _process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            }
            else
            {
                _process.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            }
            _process.StartInfo.UseShellExecute = Settings.UseShellExecuteForOutlook;
            _process.Start();
            _mainWnd = GenericWindow.FindWindow("rctrl_renwnd32", null);
            int begin = Environment.TickCount;

            Tracer._Trace("Waiting while main window is loaded");
            while ((int)_mainWnd == 0 && (Environment.TickCount - begin) < 3000)
            {
                _mainWnd = GenericWindow.FindWindow("rctrl_renwnd32", null);
            }
            Win32Declarations.SendMessage(_mainWnd, Win32Declarations.WM_ACTIVATEAPP, (IntPtr)1, IntPtr.Zero);
            Win32Declarations.SendMessage(_mainWnd, Win32Declarations.WM_NCACTIVATE, (IntPtr)0x200001, IntPtr.Zero);
            Win32Declarations.SendMessage(_mainWnd, Win32Declarations.WM_ACTIVATE, (IntPtr)0x200001, IntPtr.Zero);
            Win32Declarations.SendMessage(_mainWnd, Win32Declarations.WM_ACTIVATETOPLEVEL, (IntPtr)0x200001, (IntPtr)0x13FBE8);
            Win32Declarations.SendMessage(_mainWnd, Win32Declarations.WM_SETFOCUS, IntPtr.Zero, IntPtr.Zero);
            _close.Enabled = true;
        }
Ejemplo n.º 2
0
        public static void SetAsDefaultHandler(string protocol, string friendlyName)
        {
            Guard.NullArgument(protocol, "protocol");
            Guard.NullArgument(friendlyName, "friendlyName");
            string protocolKey = "Software\\Classes\\" + protocol;

            if (!RegUtil.CreateSubKey(Registry.CurrentUser, protocolKey))
            {
                return;
            }
            RegUtil.SetValue(Registry.CurrentUser, protocolKey, "", "URL:" + friendlyName);
            RegUtil.SetValue(Registry.CurrentUser, protocolKey, URLProtocol, "");
            if (RegUtil.CreateSubKey(Registry.CurrentUser, protocolKey + SHELL_COMMAND))
            {
                RegUtil.SetValue(Registry.CurrentUser, protocolKey + SHELL_COMMAND, "",
                                 "\"" + Application.ExecutablePath + "\"" + " -openurl %1");
            }
            if (RegUtil.CreateSubKey(Registry.CurrentUser, protocolKey + "\\DefaultIcon"))
            {
                RegUtil.SetValue(Registry.CurrentUser, protocolKey + "\\DefaultIcon", "",
                                 "\"" + Application.ExecutablePath + "\"");
            }
        }
        private ApplyResourceChangeResult <RegistryKeyResource> DoUpdate(
            ApplyResourceChangeInput <RegistryKeyResource> input)
        {
            var oldRes = input.PriorState;
            var newRes = input.PlannedState;
            var pState = StateHelper.Deserialize <PrivateState>(input.PlannedPrivate);

            _log.LogInformation($"Updating registry key at [{newRes.Root}][{newRes.Path}]");
            RegistryKey root   = RegUtil.ParseRootKey(newRes.Root);
            RegistryKey newKey = root.OpenSubKey(newRes.Path, true);

            if (newKey == null)
            {
                _log.LogInformation("Existing key does not exist, creating");
                newKey = root.CreateSubKey(newRes.Path, true);
                pState.RegistryKeyCreated = true;
            }

            var valDiffs = ResolveValueDiffs(oldRes.Entries, newRes.Entries);

            using (var regKey = newKey)
            {
                ApplyValueDiffs(regKey,
                                toDelKeys: valDiffs.toDel,
                                toDel: oldRes.Entries,
                                toAddKeys: valDiffs.toAdd,
                                toAdd: newRes.Entries,
                                toUpdKeys: valDiffs.toUpd,
                                toUpd: newRes.Entries);
            }

            return(new ApplyResourceChangeResult <RegistryKeyResource>
            {
                NewState = input.PlannedState,
                Private = StateHelper.Serialize(pState),
            });
        }
        public FrmMain()
        {
            //RegUtil.SetIEBrowserTempPath();
            InitializeComponent();
            //HttpClient.UsedFidder = true;
            //RegUtil.SetIEBrowserTempPathEnd();
            WebShow.ScriptErrorsSuppressed = true;

            WebShow.DocumentCompleted += WebShow_DocumentCompleted;
            WebShow.NewWindow         += WebShow_NewWindow;
            BtnShowBuyList.Click      += (x, xx) => {
                TryLoadBill(true);
            };
            ipWebShowUrl.KeyPress += IpWebShowUrl_KeyPress;
            var t = new Thread(() => {
                while (true)
                {
                    Thread.Sleep(200);
                    CheckNewCmd();
                }
            })
            {
                IsBackground = true
            };

            this.Show();
            int[] tmpBounds = RegUtil.GetFormPos(this);
            this.Left   = tmpBounds[0];
            this.Top    = tmpBounds[1];
            this.Width  = tmpBounds[2];
            this.Height = tmpBounds[3];
            if (Tcp == null || Tcp.client == null || !Tcp.client.Connected)
            {
                this.Close();
            }
            t.Start();
        }
        private ApplyResourceChangeResult <RegistryKeyResource> DoDelete(
            ApplyResourceChangeInput <RegistryKeyResource> input)
        {
            var oldRes = input.PriorState;
            var pState = StateHelper.Deserialize <PrivateState>(input.PlannedPrivate);

            _log.LogInformation($"Deleting registry key at [{oldRes.Root}][{oldRes.Path}]");
            RegistryKey root   = RegUtil.ParseRootKey(oldRes.Root);
            RegistryKey oldKey = root.OpenSubKey(oldRes.Path, true);

            if (oldKey != null)
            {
                string delKey = null;
                using (var regKey = oldKey)
                {
                    ApplyValueDiffs(regKey, toDel: oldRes.Entries);

                    var subKeysLen = oldKey.GetSubKeyNames()?.Length ?? 0;
                    var valuesLen  = oldKey.GetValueNames()?.Length ?? 0;
                    var forceDel   = oldRes.ForceOnDelete ?? false;

                    if (!(pState?.RegistryKeyCreated ?? false))
                    {
                        _log.LogWarning("registry key was not created by us");
                    }
                    if (subKeysLen > 0)
                    {
                        _log.LogWarning($"registry key still has [{subKeysLen}] subkey(s)");
                    }
                    if (valuesLen > 0)
                    {
                        _log.LogWarning($"registry key still has [{valuesLen}] value(s)");
                    }

                    if (!(pState?.RegistryKeyCreated ?? false) || subKeysLen > 0 || valuesLen > 0)
                    {
                        if (forceDel)
                        {
                            _log.LogWarning("forced delete specified");
                            delKey = oldKey.Name;
                        }
                        else
                        {
                            _log.LogWarning("reg key was not created by us or is not empty, SKIPPING delete");
                        }
                    }
                    else
                    {
                        delKey = oldKey.Name;
                    }
                }

                if (delKey != null)
                {
                    var openParent = RegUtil.OpenParentWithName(delKey, true);
                    if (openParent == null)
                    {
                        _log.LogWarning($"Cannot delete Registry Key [{delKey}], malformed path");
                    }
                    else
                    {
                        var(delRoot, parent, name) = openParent.Value;
                        _log.LogInformation($"Deleting Registry Key [{name}] under [{(parent??delRoot).Name}] ({delRoot.Name})");
                        using (var regKey = parent)
                        {
                            regKey.DeleteSubKeyTree(name, false);
                        }
                    }
                }
            }
            else
            {
                _log.LogInformation("Could not open existing, prior reg key, skipping");
            }

            return(new ApplyResourceChangeResult <RegistryKeyResource>
            {
                NewState = input.PlannedState,
                Private = null,
            });
        }
Ejemplo n.º 6
0
        private void UploadMachineInfoOnNetConn()
        {
            //this.EventLog.WriteEntry(String.Format("CDKey:{0}, MachineCode:{1}", cdKey, mc), EventLogEntryType.Information);

            //string mc = myWcfService.GetMachineCode();
            //this.EventLog.WriteEntry(String.Format("GetMachineCode success, value is {0}", mc), EventLogEntryType.Information);
            try
            {
                // checked if all infomration are available
                if (string.IsNullOrEmpty(RegConfig.Cdkey) ||
                    string.IsNullOrEmpty(RegConfig.MachineCode) ||
                    string.IsNullOrEmpty(RegConfig.FacName) ||
                    string.IsNullOrEmpty(RegConfig.HostLink)
                    )
                {
                    InitReadReg();
                    return;
                }

                var customerData = GetNewCustomer(String.Format("{0}/GetCustomerInfo?MachineCode={1}", RegConfig.HostLink, RegConfig.MachineCode));
                if (customerData == null)
                {
                    return;
                }


                if (RegConfig.ValidKeyInfo == null)
                {
                    //this.EventLog.WriteEntry(String.Format("Calling UpdateValidKeyInfoByCDKey"), EventLogEntryType.Information);
                    try
                    {
                        UpdateValidKeyInfoByCDKey();
                    }
                    catch (Exception ex)
                    {
                        this.EventLog.WriteEntry(String.Format("After Calling UpdateValidKeyInfoByCDKey, Excpetoin: {0}", ex.Message), EventLogEntryType.Information);
                    }
                }

                if (RegConfig.ValidKeyInfo == null)
                {
                    RegConfig.KeyStatus = "密钥格式错误";
                }
                else if (RegConfig.ValidKeyInfo.Features[0])
                {
                    RegConfig.KeyStatus = "永久密钥";
                }
                else if (!RegConfig.ValidKeyInfo.IsValid || !RegConfig.ValidKeyInfo.IsOnRightMachine || RegConfig.ValidKeyInfo.IsExpired)
                {
                    //this.EventLog.WriteEntry(String.Format("Fail to get info from cdkey {0}, IsValid: {1}, IsOnRightMachine: {2}", RegConfig.Cdkey,
                    //    RegConfig.ValidKeyInfo.IsValid,
                    //    RegConfig.ValidKeyInfo.IsOnRightMachine),
                    //    EventLogEntryType.Error
                    //    );

                    RegConfig.KeyStatus = "密钥失效";
                }
                else
                {
                    RegConfig.KeyStatus = "密钥正常";
                }


                //this.EventLog.WriteEntry(String.Format("After judage ValidKeyInfo"), EventLogEntryType.Information);


                string CreationDate = null;
                string ValidDate    = null;
                // Update RegConfig.ValidKeyInfo by read new cdkey from Reg
                try
                {
                    if (RegConfig.ValidKeyInfo != null)
                    {
                        // This coversion may cause issue
                        CreationDate = RegConfig.ValidKeyInfo.CreationDate.ToShortDateString();
                        ValidDate    = RegConfig.ValidKeyInfo.CreationDate.AddDays(RegConfig.ValidKeyInfo.SetTime).ToShortDateString();
                    }
                }
                catch (Exception ex)
                {
                    this.EventLog.WriteEntry(String.Format("Convert Date string excption: {0}", ex.Message), EventLogEntryType.Information);
                }

                //this.EventLog.WriteEntry(String.Format("CreationDate: {0}", CreationDate), EventLogEntryType.Information);
                //this.EventLog.WriteEntry(String.Format("ValidDate: {0}", ValidDate), EventLogEntryType.Information);

                //this.EventLog.WriteEntry(String.Format("Check web table"), EventLogEntryType.Information);

                //DateTime now = DateTime.Now;
                //string nowToNodeJs = now.ToString("s") + "Z";

                //this.EventLog.WriteEntry(String.Format("After judge CreationDate"), EventLogEntryType.Information);


                if (customerData.result.Count == 0)
                {
                    //this.EventLog.WriteEntry(String.Format("Check web table finished"), EventLogEntryType.Information);

                    // No customer rocord found from db table "Customers", need to upload

                    //GetUrltoHtml("http://*****:*****@"SOFTWARE\Wow6432Node\CamAligner", "CDKey", newCDKey) == false)
                        {
                            this.EventLog.WriteEntry(String.Format("CDKey write to reg Fail"), EventLogEntryType.Error);
                        }

                        // Reload Config and Reg
                        InitReadReg();
                        //this.EventLog.WriteEntry(String.Format("After Re-generate CDKey, cdkey {0}, machinecode {1}", RegConfig.Cdkey, int.Parse(RegConfig.MachineCode)), EventLogEntryType.Information);


                        UpdateValidKeyInfoByCDKey();

                        //this.EventLog.WriteEntry(String.Format("After Rereload cdkey and get key info"), EventLogEntryType.Information);


                        // update cdkey to web database
                        // Run http://nirovm2-pc:3000/UpdateCDKey?MachineCode=92040&CDKey=KTZEY-UBGPZ-REXIG-INWXB to update
                        string updateCDKeyInfo = string.Format("{0}/UpdateCDKey?MachineCode={1}&CDKey={2}&MachineStatus={3}", RegConfig.HostLink, RegConfig.MachineCode, newCDKey, RegConfig.KeyStatus);

                        // Update cdkey on web mongo db
                        updateResult = GetNewUpdateResult(updateCDKeyInfo);
                        if (updateResult.result.ok != 1)
                        {
                            this.EventLog.WriteEntry(String.Format("Update CDKey failed"), EventLogEntryType.Information);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.EventLog.WriteEntry(ex.ToString(), EventLogEntryType.Information);
            }
        }
Ejemplo n.º 7
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            List <Item> saveItems = new List <Item>();

            for (int i = 0; i < SettingDataGridView.RowCount; i++)
            {
                if (SettingDataGridView[ColumnName.Index, i].Value.Equals(string.Empty))
                {
                    MessageBox.Show(string.Format("第{0}个测试项名称未填写", i + 1));
                    return;
                }
                else if (SettingDataGridView[ColumnExecute.Index, i].Value.Equals(string.Empty))
                {
                    MessageBox.Show(string.Format("第{0}个测试项执行文件位置未填写", i + 1));
                    return;
                }
                else if (SettingDataGridView[ColumnTimeOut.Index, i].Value.Equals(string.Empty) || !RegUtil.IsNumber(SettingDataGridView[ColumnTimeOut.Index, i].Value))
                {
                    SettingDataGridView[ColumnTimeOut.Index, i].Value = 3000;
                }
                else if (SettingDataGridView[ColumnRepeatCount.Index, i].Value.Equals(string.Empty) || !RegUtil.IsNumber(SettingDataGridView[ColumnRepeatCount.Index, i].Value))
                {
                    SettingDataGridView[ColumnRepeatCount.Index, i].Value = 1;
                }
                Item item = new Item();
                item.Index          = i + 1;
                item.ItemName       = (string)SettingDataGridView[ColumnName.Index, i].Value;
                item.ExecutablePath = (string)SettingDataGridView[ColumnExecute.Index, i].Value;
                item.Parameters     = (string)SettingDataGridView[ColumnParamerters.Index, i].Value;
                item.TimeOut        = (int)SettingDataGridView[ColumnTimeOut.Index, i].Value;
                item.RepeatCount    = (int)SettingDataGridView[ColumnRepeatCount.Index, i].Value;
                item.NeedTest       = (bool)SettingDataGridView[ColumnNeedTest.Index, i].Value;
                saveItems.Add(item);
            }
            DataBaseManager.GetInstance().Init(PathUtil.GetConfigPath() + targetDataBase);
            DataBaseManager.GetInstance().SetData(saveItems, ItemManager.DATABASE_TABLE_ITEM_NAME);
            DataBaseManager.GetInstance().Deinit();
            ItemManager.GetItemManager().InitWithConfig(PathUtil.GetConfigPath() + targetDataBase);
            DialogResult = DialogResult.OK;
            Close();
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
 private void SetTransparency(Double transparency)
 {
     RegUtil.CreateRegKey("Transparency", transparency.ToString(CultureInfo.InvariantCulture));
     SMWidgetForm.Opacity = transparency;
     _ptn.Opacity         = Math.Min(transparency + 0.2, 1);
 }
Ejemplo n.º 10
0
 private void SetBgColor(Color color)
 {
     RegUtil.CreateRegKey("BgColor", color.ToString());
     MainGrid.Background = new SolidColorBrush(color);
 }
Ejemplo n.º 11
0
        /// <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;
            }
        }
Ejemplo n.º 12
0
 private void Form1_FormClosed(object sender, FormClosedEventArgs e)
 {
     RegUtil.SetFormPos(this);
     InfoShow.Dispose();
 }