Example #1
0
        private void ctxMnuComputer_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            Logger.EnteringMethod();
            Credentials cred = Credentials.GetInstance();

            lblCredentials.Text = cred.CredentialNotice;
            Logger.Write(lblCredentials);

            List <ADComputer>  targetComputers = new List <ADComputer>();
            FrmRemoteExecution remoteExecution = new FrmRemoteExecution();

            Logger.Write(dtGrdVResult.SelectedRows.Count + " computers selected.");

            foreach (DataGridViewRow row in dtGrdVResult.SelectedRows)
            {
                Logger.Write("Selecting " + row.Cells[0].Value.ToString());
                targetComputers.Add((ADComputer)row.Cells[0].Value);
            }

            ctxMnuComputer.Hide();
            switch (e.ClickedItem.Name)
            {
            case "GetWsusClientID":
                btnGetSusClientID_Click(null, null);
                break;

            case "ResetWsusClientID":
                btnResetWsusClientID_Click(null, null);
                break;

            case "StartService":
                Logger.Write("Start Service");
                if (dtGrdVResult.SelectedRows.Count != 0)
                {
                    if (cred.InitializeCredential() == false)
                    {
                        return;
                    }
                }
                _aborting = false;
                ManageService("wuauserv", "StartService", cred.Login, cred.Password);
                break;

            case "StopService":
                Logger.Write("Stop Service");
                if (dtGrdVResult.SelectedRows.Count != 0)
                {
                    if (cred.InitializeCredential() == false)
                    {
                        return;
                    }
                }
                _aborting = false;
                ManageService("wuauserv", "StopService", cred.Login, cred.Password);
                break;

            case "RestartService":
                Logger.Write("Restart Service");
                if (dtGrdVResult.SelectedRows.Count != 0)
                {
                    if (cred.InitializeCredential() == false)
                    {
                        return;
                    }
                }
                _aborting = false;
                ManageService("wuauserv", "RestartService", cred.Login, cred.Password);
                break;

            case "QueryServiceStatus":
                Logger.Write("Querying Service Status");
                this.Cursor = Cursors.WaitCursor;
                _wrongCrendentialsWatcher = new WrongCredentialsWatcher();
                _aborting = false;
                GetWuAuServiceStatus();
                this.Cursor = Cursors.Default;
                break;

            case "ShowWindowsUpdateLog":
                Logger.Write("Show WindowsUPdateLog");
                if (cred.InitializeCredential() == false)
                {
                    return;
                }
                this.Cursor = Cursors.WaitCursor;
                ADComputer computer = new ADComputer(dtGrdVResult.SelectedRows[0].Cells["ComputerName"].Value.ToString());
                if (!chkBxDontPing.Checked && !computer.Ping((int)nupPingTimeout.Value))
                {
                    MessageBox.Show(resMan.GetString("ComputerUnreachable"));
                }
                else
                {
                    computer.OpenWindowsUpdateLog(cred.Login, cred.Password);
                }
                this.Cursor = Cursors.Default;
                break;

            case "SendDetectNow":
                Logger.Write("Send DetectNow");
                remoteExecution.Show(this);
                remoteExecution.SendDetectNow(targetComputers, cred.Login, cred.Password);
                break;

            case "SendReportNow":
                Logger.Write("Send ReportNow");
                remoteExecution.Show(this);
                remoteExecution.SendReportNow(targetComputers, cred.Login, cred.Password);
                break;

            case "SendRebootNow":
                Logger.Write("Send RebootNow");
                FrmRebootCommand rebootCommand = new FrmRebootCommand(targetComputers, cred.Login, cred.Password);
                rebootCommand.Show();
                break;

            default:
                Logger.Write("**** Unable to detect the command");
                break;
            }
        }
        private void ctxMnuComputer_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            Logger.EnteringMethod(e.ClickedItem.Name);
            List <ADComputer>  targetComputers = new List <ADComputer>();
            FrmRemoteExecution remoteExecution = new FrmRemoteExecution();

            foreach (DataGridViewRow row in dGVComputer.SelectedRows)
            {
                if (row.Visible)
                {
                    targetComputers.Add((ADComputer)row.Cells["ComputerName"].Value);
                }
            }
            ctxMnuComputer.Hide();
            Credentials cred = Credentials.GetInstance();

            if (targetComputers.Count != 0)
            {
                if (cred.InitializeCredential() == false)
                {
                    return;
                }
            }
            lblCredentialNotice.Text = cred.CredentialNotice;
            Logger.Write(lblCredentialNotice);

            switch (e.ClickedItem.Name)
            {
            case "DetectNow":
                remoteExecution.Show(this);
                remoteExecution.SendDetectNow(targetComputers, cred.Login, cred.Password);
                break;

            case "ReportNow":
                remoteExecution.Show(this);
                remoteExecution.SendReportNow(targetComputers, cred.Login, cred.Password);
                break;

            case "RebootNow":
                FrmRebootCommand rebootCommand = new FrmRebootCommand(targetComputers, cred.Login, cred.Password);
                rebootCommand.Show();
                break;

            case "ShowPendingUpdates":
                System.Diagnostics.ProcessStartInfo startInfo      = new System.Diagnostics.ProcessStartInfo();
                System.Security.SecureString        securePassword = new System.Security.SecureString();

                startInfo.FileName = Environment.CurrentDirectory + @"\ShowPendingUpdates.exe";
                if (!System.IO.File.Exists(startInfo.FileName))
                {
                    Logger.Write("Unable to find : " + startInfo.FileName);
                    MessageBox.Show(resMan.GetString("UnableToFindShowPendingUpdates"));
                }
                else
                {
                    startInfo.Arguments = targetComputers[0].Name;
                    if (!string.IsNullOrEmpty(cred.Login) && !string.IsNullOrEmpty(cred.Password))
                    {
                        foreach (Char letter in cred.Password)
                        {
                            securePassword.AppendChar(letter);
                        }
                        startInfo.UserName = cred.Login;
                        startInfo.Password = securePassword;
                        startInfo.Domain   = ADHelper.GetDomainName();
                    }
                    startInfo.UseShellExecute  = false;
                    startInfo.WorkingDirectory = Environment.CurrentDirectory;
                    try
                    {
                        System.Diagnostics.Process.Start(startInfo);
                    }
                    catch (Exception ex)
                    {
                        Logger.Write("**** " + ex.Message);
                        MessageBox.Show(ex.Message);
                    }
                }
                break;

            case "InstallPendingUpdates":
                FrmInstallPendingUpdatesNow installPendingUpdates = new FrmInstallPendingUpdatesNow();
                installPendingUpdates.Username  = cred.Login;
                installPendingUpdates.Password  = cred.Password;
                installPendingUpdates.Computers = targetComputers;
                installPendingUpdates.ShowDialog();
                break;

            case "ShowCurrentLogonUser":
                this.Cursor = Cursors.WaitCursor;
                ADComputer remoteComputer = new ADComputer(dGVComputer.SelectedRows[0].Cells["ComputerName"].Value.ToString());
                string     logonUser      = remoteComputer.GetCurrentLogonUser(cred.Login, cred.Password);
                if (!string.IsNullOrEmpty(logonUser))
                {
                    MessageBox.Show(resMan.GetString("CurrentLogonUserIs") + " : " + logonUser);
                }
                else
                {
                    MessageBox.Show(resMan.GetString("UnableToGetLogonUser"));
                }
                this.Cursor = Cursors.Default;
                break;

            case "ShowWindowsUpdateLog":
                this.Cursor = Cursors.WaitCursor;
                ADComputer computer = new ADComputer(dGVComputer.SelectedRows[0].Cells["ComputerName"].Value.ToString());
                if (!computer.Ping(100))
                {
                    MessageBox.Show(resMan.GetString("ComputerUnreachable"));
                }
                else
                {
                    computer.OpenWindowsUpdateLog(cred.Login, cred.Password);
                }
                this.Cursor = Cursors.Default;
                break;

            case "CleanSoftwareDistributionFolder":
                this.Cursor = Cursors.WaitCursor;
                FrmCleanSoftwareDistributionFolder frmCleanSoftwareDistributionFolder = new FrmCleanSoftwareDistributionFolder(targetComputers, cred.Login, cred.Password);
                frmCleanSoftwareDistributionFolder.ShowDialog();
                this.Cursor = Cursors.Default;
                break;

            default:
                break;
            }
        }