Пример #1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.Text == "")
            {
                DialogResult result = MessageBox.Show("You did not select anything to restart!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (checkedListBox1.SelectedIndex == -1)
            {
                DialogResult result = MessageBox.Show("You did not select anything to restart!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                // Gather all checked items
                if (checkedListBox1.CheckedItems.Count != 0)
                {
                    int    i;
                    string s;
                    s = "Are you sure you want to restart the following:\n";
                    for (i = 0; i <= (checkedListBox1.Items.Count - 1); i++)
                    {
                        if (checkedListBox1.GetItemChecked(i))
                        {
                            s = s + checkedListBox1.Items[i].ToString() + "\n";
                        }
                    }
                    DialogResult result = MessageBox.Show(s, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    for (i = 0; i <= (checkedListBox1.Items.Count - 1); i++)
                    {
                        if (checkedListBox1.GetItemChecked(i))
                        {
                            if (result == DialogResult.Yes)
                            {
                                //Code for Yes

                                ProgressDialog progressDialog = new ProgressDialog();
                                for (int n = 0; n < 100; n++)
                                {
                                    progressDialog.UpdateProgress(n); // Update progress in progressDialog
                                }


                                toolStripStatusLabel2.Text = "Restarting:";
                                toolStripStatusLabel1.Text = ConfigurationManager.AppSettings.Get(checkedListBox1.Items[i].ToString());
                                toolStripStatusLabel3.Text = checkedListBox1.Items[i].ToString();
                                progressDialog.ChangeLabel("Restarting: " + toolStripStatusLabel3.Text);
                                progressDialog.Show();
                                Reboot();

                                toolStripStatusLabel2.Text = "Status:";
                                toolStripStatusLabel3.Text = "Idle";

                                progressDialog.Close();
                            }
                            else if (result == DialogResult.No)
                            {
                                //code for No
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (button1.Text == "Enable Stitching")
                {
                    XDocument xDoc = XDocument.Load(Descanso);
                    xDoc.Descendants("stitchingEnabledSetting").First().Value = "True";
                    xDoc.Save(Descanso);

                    Cursor.Current = Cursors.WaitCursor;
                    int i = 1;
                    while (i < 5)
                    {
                        string Value = "7112";

                        //Change Registry Value to 7112

                        string ServerName  = ConfigurationManager.AppSettings.Get("A" + i);
                        string regKeyToGet = @"SOFTWARE\Wow6432Node\Memjet\Aspen\Controller";
                        string keyToRead   = "StitchOverlapMicrons";

                        // Connection Login if needed

                        ConnectionOptions oConn = new ConnectionOptions();
                        //oConn.Username = "******";
                        //oConn.Password = "******";
                        System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" + ServerName + @"\root\default", oConn);

                        scope.Options.EnablePrivileges = true;
                        scope.Connect();

                        ManagementClass      registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
                        ManagementBaseObject inParams = registry.GetMethodParameters("CreateKey");
                        inParams["sSubKeyName"] = regKeyToGet;
                        ManagementBaseObject outParams = registry.InvokeMethod("CreateKey", inParams, null);

                        ManagementBaseObject inParams6 = registry.GetMethodParameters("SetStringValue");
                        inParams6["sSubKeyName"] = regKeyToGet;
                        inParams6["sValueName"]  = keyToRead;
                        inParams6["sValue"]      = Value;
                        ManagementBaseObject outParams6 = registry.InvokeMethod("SetStringValue", inParams6, null);

                        i++;
                    }


                    Cursor.Current = Cursors.Default;
                }
                else if (button1.Text == "Disable Stitching")
                {
                    XDocument xDoc = XDocument.Load(Descanso);
                    xDoc.Descendants("stitchingEnabledSetting").First().Value = "False";
                    xDoc.Save(Descanso);

                    Cursor.Current = Cursors.WaitCursor;
                    int i = 1;
                    while (i < 5)
                    {
                        string Value = "0";

                        //Change Registry Value to 0

                        string ServerName  = ConfigurationManager.AppSettings.Get("A" + i);
                        string regKeyToGet = @"SOFTWARE\Wow6432Node\Memjet\Aspen\Controller";
                        string keyToRead   = "StitchOverlapMicrons";

                        // Connection Login if needed

                        ConnectionOptions oConn = new ConnectionOptions();
                        //oConn.Username = "******";
                        //oConn.Password = "******";
                        System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" + ServerName + @"\root\default", oConn);

                        scope.Options.EnablePrivileges = true;
                        scope.Connect();

                        ManagementClass      registry = new ManagementClass(scope, new ManagementPath("StdRegProv"), null);
                        ManagementBaseObject inParams = registry.GetMethodParameters("CreateKey");
                        // inParams["hDefKey"] = (UInt32)2147483650;
                        inParams["sSubKeyName"] = regKeyToGet;
                        ManagementBaseObject outParams = registry.InvokeMethod("CreateKey", inParams, null);

                        ManagementBaseObject inParams6 = registry.GetMethodParameters("SetStringValue");
                        //inParams6["hDefKey"] = 2147483650;
                        inParams6["sSubKeyName"] = regKeyToGet;
                        inParams6["sValueName"]  = keyToRead;
                        inParams6["sValue"]      = Value;
                        ManagementBaseObject outParams6 = registry.InvokeMethod("SetStringValue", inParams6, null);

                        i++;
                    }
                    Cursor.Current = Cursors.Default;
                }
                DialogResult result = MessageBox.Show("You need to restart the Aspen service on all 4 machines\nWould you like to do that now?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    ProgressDialog progressDialog = new ProgressDialog();
                    for (int n = 0; n < 100; n++)
                    {
                        progressDialog.UpdateProgress(n); // Update progress in progressDialog
                    }
                    progressDialog.ChangeLabel("Restarting: All Aspen Services");
                    progressDialog.Show();

                    RestartAspen();

                    progressDialog.Close();
                    Cursor.Current = Cursors.Default;
                }
                CheckReg();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }