Example #1
0
        private void StartResetSusClientID()
        {
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Properties.Settings.Default.Language);

            Credentials cred = Credentials.GetInstance();

            if (dtGrdVResult.SelectedRows.Count != 0)
            {
                if (cred.InitializeCredential() == false)
                {
                    return;
                }
            }
            Logger.Write(lblCredentials);

            Action startAction = () => { lblCredentials.Text = cred.CredentialNotice; };

            if (!_closing)
            {
                this.Invoke(startAction);
            }

            System.Threading.CountdownEvent countEvent = new System.Threading.CountdownEvent(1);

            foreach (DataGridViewRow row in dtGrdVResult.SelectedRows)
            {
                countEvent.AddCount();
                ASyncClientParameters parameters = new ASyncClientParameters();
                parameters.RowIndex   = row.Index;
                parameters.Login      = cred.Login;
                parameters.Password   = cred.Password;
                parameters.CountEvent = countEvent;

                if (!_closing & !_aborting)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(ResetSusClientID, parameters);
                }
            }
            countEvent.Signal();
            countEvent.Wait(10000 * dtGrdVResult.SelectedRows.Count);

            if (!_closing && !_aborting)
            {
                SearchDuplicateWsusClientID();
            }

            Action endAction = () => { ChangeUIAccess(true); };

            if (!_closing)
            {
                this.Invoke(endAction);
            }
        }
Example #2
0
        private void ResetSusClientID(object obj)
        {
            ASyncClientParameters parameters = (ASyncClientParameters)obj;

            try
            {
                object[] args = new object[3];

                ADComputer computer = (ADComputer)dtGrdVResult.Rows[parameters.RowIndex].Cells["ComputerName"].Value;
                args[0] = resMan.GetString("FailedToSendCommand");
                args[1] = parameters.RowIndex;
                args[2] = "SusClientID";
                if (!_closing && !_aborting && !chkBxDontPing.Checked && !computer.Ping((int)nupPingTimeout.Value))
                {
                    args[0] = resMan.GetString("Unreachable");
                }
                else
                {
                    if (!_closing && !_aborting)
                    {
                        lock (_ResetSusClientIDLocker)
                        {
                            try
                            {
                                if (!_closing && !_aborting && !_wrongCrendentialsWatcher.IsAbortRequested)
                                {
                                    if (computer.ResetWsusClientID(parameters.Login, parameters.Password))
                                    {
                                        args[0] = resMan.GetString("Reset");
                                    }
                                    else
                                    {
                                        args[0] = resMan.GetString("Failed");
                                    }
                                }
                                else
                                {
                                    args[0] = resMan.GetString("Aborted");
                                }
                            }
                            catch (UnauthorizedAccessException)
                            {
                                _wrongCrendentialsWatcher.IsWrongCredentials = true;

                                if (!_wrongCrendentialsWatcher.ContinueWithFailedCredentials)
                                {
                                    if (MessageBox.Show(resMan.GetString("CredentialFailed"), resMan.GetString("FailedToConnect"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                                    {
                                        Logger.Write("interrupt on failed credentials.");
                                        _wrongCrendentialsWatcher.IsAbortRequested = true;
                                        args[0] = resMan.GetString("Aborted");
                                    }
                                    else
                                    {
                                        Logger.Write("Continue with bad credentials.");
                                        _wrongCrendentialsWatcher.ContinueWithFailedCredentials = true;
                                        args[0] = resMan.GetString("FailedToConnect");
                                    }
                                }
                                else
                                {
                                    args[0] = resMan.GetString("FailedToConnect");
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.Write(ex.Message);
                                args[0] = resMan.GetString("FailedToSendCommand");
                            }
                        }
                    }
                    else
                    {
                        args[0] = resMan.GetString("Aborted");
                    }
                }
                UpdateRow(args);
            }
            catch (Exception) { }
            finally { parameters.CountEvent.Signal(); }
        }
Example #3
0
        private void QueryWuAuServiceStatus(object obj)
        {
            char[] separator = new char[1] {
                ';'
            };
            ASyncClientParameters parameters = (ASyncClientParameters)obj;

            try
            {
                int      index    = parameters.RowIndex;
                string   login    = parameters.Login;
                string   password = parameters.Password;
                object[] args     = new object[3];

                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Properties.Settings.Default.Language);
                ADComputer computer = (ADComputer)dtGrdVResult.Rows[index].Cells["ComputerName"].Value;
                args[0] = resMan.GetString("FailedToConnect");
                args[1] = index;
                args[2] = "ServiceStatus";

                if (!_closing && !_aborting && !chkBxDontPing.Checked && !computer.Ping((int)nupPingTimeout.Value))
                {
                    args[0] = resMan.GetString("Unreachable");
                }
                else
                {
                    if (!_closing && !_aborting)
                    {
                        lock (_QueryWuAuSrvStatusLocker)
                        {
                            string result = string.Empty;
                            try
                            {
                                if (!_closing && !_aborting && !_wrongCrendentialsWatcher.IsAbortRequested)
                                {
                                    result = computer.QueryWuAuSrvStatus(login, password);
                                    if (result.IndexOf(';') != -1)
                                    {
                                        string[] tab = result.Split(separator);
                                        if (tab != null && tab.Length == 2)
                                        {
                                            result = resMan.GetString(tab[0]) + " " + tab[1];
                                        }
                                    }
                                    args[0] = result;
                                }
                                else
                                {
                                    args[0] = resMan.GetString("Aborted");
                                }
                            }
                            catch (UnauthorizedAccessException)
                            {
                                _wrongCrendentialsWatcher.IsWrongCredentials = true;

                                if (!_wrongCrendentialsWatcher.ContinueWithFailedCredentials)
                                {
                                    if (MessageBox.Show(resMan.GetString("CredentialFailed"), resMan.GetString("FailedToConnect"), MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
                                    {
                                        Logger.Write("interrupt on failed credentials.");
                                        _wrongCrendentialsWatcher.IsAbortRequested = true;
                                        args[0] = resMan.GetString("Aborted");
                                    }
                                    else
                                    {
                                        Logger.Write("Continue with bad credentials.");
                                        _wrongCrendentialsWatcher.ContinueWithFailedCredentials = true;
                                        args[0] = resMan.GetString("FailedToConnect");
                                    }
                                }
                                else
                                {
                                    args[0] = resMan.GetString("FailedToConnect");
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.Write(ex.Message);
                                args[0] = resMan.GetString("FailedToSendCommand");
                            }
                        }
                    }
                    else
                    {
                        args[0] = resMan.GetString("Aborted");
                    }
                }
                UpdateRow(args);
            }
            catch (Exception) { }
            finally { parameters.CountEvent.Signal(); }
        }