Exemplo n.º 1
0
        public WSUS()
        {
            // I use impersonation to use other logon than mine. Remove the following "using" if not needed
            using (Impersonation.LogonUser("mydomain.local", "admin_account_wsus", "Password", LogonType.Batch))
            {
                ComputerTargetScope      scope   = new ComputerTargetScope();
                IUpdateServer            server  = AdminProxy.GetUpdateServer("wsus_server.mydomain.local", false, 80);
                ComputerTargetCollection targets = server.GetComputerTargets(scope);
                // Search
                targets = server.SearchComputerTargets("any_server_name_or_ip");

                // To get only on server FindTarget method
                IComputerTarget target = FindTarget(targets, "any_server_name_or_ip");
                Console.WriteLine(target.FullDomainName);
                IUpdateSummary summary      = target.GetUpdateInstallationSummary();
                UpdateScope    _updateScope = new UpdateScope();
                // See in UpdateInstallationStates all other properties criteria
                _updateScope.IncludedInstallationStates = UpdateInstallationStates.Downloaded;
                UpdateInstallationInfoCollection updatesInfo = target.GetUpdateInstallationInfoPerUpdate(_updateScope);

                int updateCount = updatesInfo.Count;

                foreach (IUpdateInstallationInfo updateInfo in updatesInfo)
                {
                    Console.WriteLine(updateInfo.GetUpdate().Title);
                }
            }
        }
Exemplo n.º 2
0
        public static List <string> GetWSUSlist(params string[] list)
        {
            List <string> result = new List <string>(200); //не забудь изменить количество

            string namehost   = list[0];                   //имя Пк, на котором будем искать string  = "example1";
            string servername = list[1];                   //имя сервера string  = "WIN-E1U41FA6E55";
            string Username   = list[2];
            string Password   = list[3];

            try
            {
                ComputerTargetScope      scope   = new ComputerTargetScope();
                IUpdateServer            server  = AdminProxy.GetUpdateServer(servername, false, 8530);
                ComputerTargetCollection targets = server.GetComputerTargets(scope);
                // Search
                targets = server.SearchComputerTargets(namehost);

                // To get only on server FindTarget method
                IComputerTarget target = FindTarget(targets, namehost);
                result.Add("Имя ПК: " + target.FullDomainName);

                IUpdateSummary summary      = target.GetUpdateInstallationSummary();
                UpdateScope    _updateScope = new UpdateScope();
                // See in UpdateInstallationStates all other properties criteria

                //_updateScope.IncludedInstallationStates = UpdateInstallationStates.Downloaded;
                UpdateInstallationInfoCollection updatesInfo = target.GetUpdateInstallationInfoPerUpdate(_updateScope);

                int updateCount = updatesInfo.Count;

                result.Add("Кол -во найденных обновлений - " + updateCount);

                foreach (IUpdateInstallationInfo updateInfo in updatesInfo)
                {
                    result.Add(updateInfo.GetUpdate().Title);
                }
            }

            catch (Exception ex)
            {
                result.Add("Что-то пошло не так: " + ex.Message);
            }

            return(result);
        }
        private void DisplayInstalledUpdates()
        {
            Logger.EnteringMethod();
            if (SelectedRows != null && SelectedRows.Count != 0)
            {
                List <Guid>   installedUpdate = new List <Guid>();
                StringBuilder builder         = new StringBuilder();

                DataGridViewRow[] selectedRows = new DataGridViewRow[SelectedRows.Count];
                SelectedRows.CopyTo(selectedRows, 0);

                for (int i = 0; i < selectedRows.Length; i++)
                {
                    try
                    {
                        if (!_aborting)
                        {
                            UpdateInstallationInfoCollection updateInfo = _wsus.GetUpdateInstallationInfo(selectedRows[i].Cells[0].Value.ToString(), InstalledAfter, InstalledBefore);

                            foreach (IUpdateInstallationInfo update in updateInfo)
                            {
                                if (!installedUpdate.Contains(update.UpdateId))
                                {
                                    installedUpdate.Add(update.UpdateId);
                                    builder.AppendLine(update.GetUpdate().Title);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Write("**** " + ex.Message);
                    }
                }
                Action action = () =>
                {
                    txtBxDetail.Text   = builder.ToString();
                    btnRefresh.Enabled = true;
                };
                if (!this.IsDisposed && !this.Disposing && !_aborting)
                {
                    this.Invoke(action);
                }
            }
        }
        private void DisplayReportASynch()
        {
            Dictionary <Guid, Company>  companies = ComputerCtrl.Companies;
            UpdateApprovalCollection    approvalsForThisGroup;
            UpdateApprovalCollection    approvalsForAllComputersGroup;
            IComputerTargetGroup        allComputerTargetGroup = _wsus.GetAllComputerTargetGroup();
            Dictionary <string, string> computers   = new Dictionary <string, string>();
            ComputerTargetScope         targetScope = new ComputerTargetScope();
            ReportResult resultToDisplay            = new ReportResult();

            if (!cancelDisplayReport && SelectedRows.Count != 0)
            {
                targetScope.ComputerTargetGroups.Add(_wsus.GetComputerGroup(ComputerCtrl.ComputerGroupID));
                targetScope.IncludeDownstreamComputerTargets = true;

                foreach (DataGridViewRow row in SelectedRows)
                {
                    if (row.Index != -1 && row.Visible)
                    {
                        string tempComputer = _wsus.GetComputerTargetByName((row.Cells["ComputerName"].Value.ToString())).Id;
                        if (tempComputer != null)
                        {
                            computers.Add(tempComputer, row.Cells["ComputerName"].Value.ToString());
                        }
                    }
                }

                foreach (Company company in companies.Values)
                {
                    if (cancelDisplayReport)
                    {
                        break;
                    }
                    foreach (Product product in company.Products.Values)
                    {
                        if (cancelDisplayReport)
                        {
                            break;
                        }
                        foreach (IUpdate update in product.Updates)
                        {
                            if (cancelDisplayReport)
                            {
                                break;
                            }
                            resultToDisplay.ResetCounters();

                            approvalsForThisGroup         = _wsus.GetUpdateApprovalStatus(ComputerCtrl.ComputerGroupID, update);
                            approvalsForAllComputersGroup = _wsus.GetUpdateApprovalStatus(allComputerTargetGroup.Id, update);
                            if ((approvalsForThisGroup.Count != 0 || approvalsForAllComputersGroup.Count != 0) && (chkBxShowSupersededUpdates.Checked || !update.IsSuperseded))
                            {
                                UpdateInstallationInfoCollection installationInfo = update.GetUpdateInstallationInfoPerComputerTarget(targetScope);
                                foreach (IUpdateInstallationInfo info in installationInfo)
                                {
                                    if (computers.ContainsKey(info.ComputerTargetId))
                                    {
                                        switch (info.UpdateInstallationState)
                                        {
                                        case UpdateInstallationState.Downloaded:
                                            resultToDisplay.DownloadedCount++;
                                            break;

                                        case UpdateInstallationState.Failed:
                                            resultToDisplay.FailedCount++;
                                            break;

                                        case UpdateInstallationState.Installed:
                                            resultToDisplay.InstalledCount++;
                                            break;

                                        case UpdateInstallationState.InstalledPendingReboot:
                                            resultToDisplay.InstalledPendingRebootCount++;
                                            break;

                                        case UpdateInstallationState.NotApplicable:
                                            resultToDisplay.NotApplicableCount++;
                                            break;

                                        case UpdateInstallationState.NotInstalled:
                                            resultToDisplay.NotInstalledCount++;
                                            break;

                                        case UpdateInstallationState.Unknown:
                                            resultToDisplay.UnknownCount++;
                                            break;

                                        default:
                                            break;
                                        }
                                    }
                                }

                                object[] args = new object[4];

                                args[0] = update.CompanyTitles[0];
                                args[1] = update.Title;
                                args[2] = ((approvalsForThisGroup.Count != 0) ? resMan.GetString(approvalsForThisGroup[0].Action.ToString()) : resMan.GetString(approvalsForAllComputersGroup[0].Action.ToString())) + ((update.IsSuperseded) ? "(" + resMan.GetString("Superseded") + ")" : string.Empty);
                                args[3] = resultToDisplay;

                                FillRow(args);
                            }
                        }
                    }
                }
                Action action = () =>
                {
                    if (dtGvReport.SortedColumn != null)
                    {
                        dtGvReport.Sort(dtGvReport.SortedColumn, (dtGvReport.SortOrder == SortOrder.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending);
                    }
                };
                this.Invoke(action);
            }
        }