public frmSUSWatch()
        {
            InitializeComponent();

            wsus = cfg.wsus;

            // Populate duplicated SUS ID grid from XML
            foreach (string susid in cfg.DefaultSusIDCollection)
            {
                DataGridViewRow r = grdSUSID.Rows[grdSUSID.Rows.Add()];

                r.Cells[susID.Index].Value = susid;
                r.Cells[susSource.Index].Value = "Previously Saved";
            }

            // Refresh display
            this.Refresh();

            // Get list of current computers
            ComputerTargetScope s = new ComputerTargetScope();
            s.IncludeDownstreamComputerTargets = true;

            ComputerTargetCollection cc = wsus.server.GetComputerTargets(s);

            // Add all existing computers to our array
            int count = 0;

            foreach (IComputerTarget c in cc)
            {
                ctc.Add(c);
                count++;
            }

            Log("Added " + count.ToString() + " computers already in database");
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
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);
        }
        public frmSUSWatch()
        {
            InitializeComponent();

            wsus = cfg.wsus;

            // Populate duplicated SUS ID grid from XML
            foreach (string susid in cfg.DefaultSusIDCollection)
            {
                DataGridViewRow r = grdSUSID.Rows[grdSUSID.Rows.Add()];

                r.Cells[susID.Index].Value     = susid;
                r.Cells[susSource.Index].Value = "Previously Saved";
            }

            // Refresh display
            this.Refresh();

            // Get list of current computers
            ComputerTargetScope s = new ComputerTargetScope();

            s.IncludeDownstreamComputerTargets = true;

            ComputerTargetCollection cc = wsus.server.GetComputerTargets(s);

            // Add all existing computers to our array
            int count = 0;

            foreach (IComputerTarget c in cc)
            {
                ctc.Add(c);
                count++;
            }

            Log("Added " + count.ToString() + " computers already in database");
        }
        private void tim_Tick(object sender, EventArgs e)
        {
            // If it's not time, decrement the progress bar and exit
            if (prg.Value > prg.Minimum)
            {
                prg.Value--;
                return;
            }

            // Time to update SUS IDs
            prg.Value = prg.Maximum;

            // Refresh display
            this.Refresh();

            // Get list of current computers
            ComputerTargetScope s = new ComputerTargetScope();
            s.IncludeDownstreamComputerTargets = true;

            ComputerTargetCollection cc = wsus.server.GetComputerTargets(s);

            // Loop through all computers to see if we already know about them
            foreach (IComputerTarget t in cc)
            {
                // Try to find a known computer
                ComputerDetail d = ctc[t];

                if (d == null)
                {
                    // We got a new one!
                    ctc.Add(t);

                    int count = ctc.SusIDCount(t.Id);
                    Log("New computer found - " + t.FullDomainName + " (ID " + t.Id + ")  " + count.ToString() + " of this ID found.");

                    // Do we have a SUS ID we've seen associated with another PC?
                    if (count > 1)
                    {
                        // Yes!  Add it to the data grid, or update the existing entry
                        DataGridViewRow r = null;

                        foreach (DataGridViewRow gr in grdSUSID.Rows)
                            if (gr.Cells[susID.Index].Value.ToString() == t.Id)
                            {
                                // Found an existing entry - note it and break
                                r = gr;
                                break;
                            }

                        // Did we find a row, or do we need to add one?
                        if (r == null)
                            // We need to add one
                            grdSUSID.Rows.Insert(0, 1);
                            r = grdSUSID.Rows[0];

                        r.Cells[susID.Index].Value = t.Id;
                        r.Cells[susCount.Index].Value = count.ToString();
                        r.Cells[susSource.Index].Value = "Detected";
                    }
                }
            }
        }
Beispiel #6
0
        private void EndpointUpdateNotCommunicating()
        {
            // Get list of computers that hasn't updated in the last week
            ComputerTargetScope cs = new ComputerTargetScope();
            cs.ToLastSyncTime = DateTime.Now.AddDays(-7);
            cs.IncludeDownstreamComputerTargets = true;

            // Update grid
            foreach (IComputerTarget c in wsus.server.GetComputerTargets(cs))
            {
                epRowData r = new epRowData("Not Communicating", c);

                AddUpdateEndpointGrid(r);
            }
        }
Beispiel #7
0
        private void EndpointUpdateDuplicateIPs()
        {
            //  Get a complete list of computers
            ComputerTargetScope cs = new ComputerTargetScope();
            cs.IncludeDownstreamComputerTargets = true;

            ComputerTargetCollection cc = wsus.server.GetComputerTargets(cs);

            // Assemble a dictionary for comparison
            Dictionary<String, String> ca = new Dictionary<String, String>();

            foreach (IComputerTarget c in cc)
            {
                ca.Add(c.Id.ToString(), c.IPAddress.ToString());
            }

            // Loop through all computers
            foreach (IComputerTarget c in cc)
            {
                string cn = c.Id.ToString();
                string ip = c.IPAddress.ToString();

                // See if we can find one with a duplicate IP address
                foreach (KeyValuePair<string,string> e in ca)
                {
                    // Do we have a different computer to the current one and does it have a duplicate IP address
                    if (cn != e.Key && ip == e.Value)
                    {
                        // Yep, it's a duplicate.
                        epRowData r = new epRowData("Duplicate IP address", c);

                        // Add it and break
                        AddUpdateEndpointGrid(r);
                        break;
                    }
                }
            }
        }
Beispiel #8
0
        private void UpdateServerReboots()
        {
            if (DateTime.Now.Subtract(lastupdaterun).Minutes > 5 || forceUpdate)
            {
                // Show updating message
                gbxWorking.Visible = true;
                this.Refresh();

                // Reset last run time
                lastupdaterun = DateTime.Now;

                // Try to get a list of computers
                ComputerTargetScope cs = new ComputerTargetScope();
                cs.IncludedInstallationStates = UpdateInstallationStates.InstalledPendingReboot;
                cs.IncludeDownstreamComputerTargets = true;
                ComputerTargetCollection comp = wsus.server.GetComputerTargets(cs);

                // Clear the list of servers and update
                lstServers.Items.Clear();

                foreach (IComputerTarget c in comp)
                {
                    // Is this a Windows Server?
                    if (c.OSDescription.ToUpper().Contains("SERVER"))
                    {
                        // Yep - include it
                        lstServers.Items.Add(c.FullDomainName);
                    }
                }

                // Reset update interval to 5 minutes
                timUpdateData.Interval = 5 * 60 * 1000;
            }
        }
        private void tim_Tick(object sender, EventArgs e)
        {
            // If it's not time, decrement the progress bar and exit
            if (prg.Value > prg.Minimum)
            {
                prg.Value--;
                return;
            }

            // Time to update SUS IDs
            prg.Value = prg.Maximum;

            // Refresh display
            this.Refresh();

            // Get list of current computers
            ComputerTargetScope s = new ComputerTargetScope();

            s.IncludeDownstreamComputerTargets = true;

            ComputerTargetCollection cc = wsus.server.GetComputerTargets(s);

            // Loop through all computers to see if we already know about them
            foreach (IComputerTarget t in cc)
            {
                // Try to find a known computer
                ComputerDetail d = ctc[t];

                if (d == null)
                {
                    // We got a new one!
                    ctc.Add(t);

                    int count = ctc.SusIDCount(t.Id);
                    Log("New computer found - " + t.FullDomainName + " (ID " + t.Id + ")  " + count.ToString() + " of this ID found.");

                    // Do we have a SUS ID we've seen associated with another PC?
                    if (count > 1)
                    {
                        // Yes!  Add it to the data grid, or update the existing entry
                        DataGridViewRow r = null;

                        foreach (DataGridViewRow gr in grdSUSID.Rows)
                        {
                            if (gr.Cells[susID.Index].Value.ToString() == t.Id)
                            {
                                // Found an existing entry - note it and break
                                r = gr;
                                break;
                            }
                        }

                        // Did we find a row, or do we need to add one?
                        if (r == null)
                        {
                            // We need to add one
                            grdSUSID.Rows.Insert(0, 1);
                        }
                        r = grdSUSID.Rows[0];

                        r.Cells[susID.Index].Value     = t.Id;
                        r.Cells[susCount.Index].Value  = count.ToString();
                        r.Cells[susSource.Index].Value = "Detected";
                    }
                }
            }
        }
        private void getClientStatus()
        {
            if (cbxWsusServer.Text == "")
            {
                MessageBox.Show("Bitte wählen Sie einen WSUS Server aus.", "Kein WSUS Server ausgewählt.");
            }
            else
            {
                if (groups.Text == "")
                {
                    MessageBox.Show("Bitte wählen Sie eine WSUS Gruppe aus.", "Keine WSUS Gruppe ausgewählt.");
                }
                else
                {
                    disableGUI();

                    IUpdateServer UpdateServer = getUpdateServer(cbxWsusServer.SelectedItem.ToString());

                    //Zu suchende Updates definieren
                    UpdateScope updtScope = new UpdateScope();
                    updtScope.FromCreationDate = dateFrom.Value;
                    updtScope.ToCreationDate = dateTo.Value.Date;
                    //updtScope.ExcludedInstallationStates = UpdateInstallationStates.NotApplicable;
                    //updtScope.IncludedInstallationStates = UpdateInstallationStates.Installed | UpdateInstallationStates.InstalledPendingReboot | UpdateInstallationStates.Failed | UpdateInstallationStates.NotInstalled | UpdateInstallationStates.Unknown | UpdateInstallationStates.Downloaded;
                    updtScope.ApprovedStates = ApprovedStates.HasStaleUpdateApprovals | ApprovedStates.LatestRevisionApproved | ApprovedStates.NotApproved;

                    ComputerTargetScope searchRange = new ComputerTargetScope();
                    searchRange.ComputerTargetGroups.Add(((WSUSGroup)groups.SelectedItem).getWSUSGroup());
                    searchRange.IncludeDownstreamComputerTargets = true;
                    searchRange.NameIncludes = txtClientFilter.Text;

                    ComputerTargetCollection myClients = UpdateServer.GetComputerTargets(searchRange);

                    foreach (IComputerTarget client in myClients)
                    {
                        int countInstalledUpdates = 0;
                        int countAllUpdates = 0;

                        IUpdateSummary updtsum = client.GetUpdateInstallationSummary(updtScope);
                        countInstalledUpdates = updtsum.InstalledCount;
                        countAllUpdates = updtsum.InstalledCount + updtsum.UnknownCount + updtsum.NotInstalledCount + updtsum.FailedCount;

                        //ermittle zugewiesene wsus gruppe des clients
                        string clientWsusGroup = "";

                        foreach (IComputerTargetGroup gp in client.GetComputerTargetGroups())
                        {
                            clientWsusGroup += gp.Name + " / ";
                        }
                        clientWsusGroup = clientWsusGroup.Remove((clientWsusGroup.Length - 3));

                        double state = 0.0;

                        if (countAllUpdates > 0 | countInstalledUpdates > 0)
                        {
                            state = ((100.0 / (double)countAllUpdates) * (double)countInstalledUpdates);
                        }

                        resultsClients.Rows.Add(client.FullDomainName.ToString(), Math.Round(state, 2), client.ComputerRole, client.LastReportedStatusTime.ToString("yyy/MM/dd - HH:mm"), clientWsusGroup, client.OSDescription + ", " + client.OSArchitecture, "Updatedetails", "Detailansicht");
                    }

                    enableGUI();
                }
            }

            resultsClients.Visible = true;
        }
        private DataTable getClientsPerUpdate(string wsusServer, UpdateRevisionId updateID)
        {
            DataTable data = new DataTable();
            data = new DataTable();

            data.Columns.Add("Computername");
            data.Columns.Add("OS");
            data.Columns.Add("lastReport");
            data.Columns.Add("UpdateStatus");

            IUpdateServer UpdateServer = getUpdateServer(wsusServer);

            ComputerTargetScope compTargetScope = new ComputerTargetScope();
            compTargetScope.ComputerTargetGroups.Add(((WSUSGroup)groups.SelectedItem).getWSUSGroup());
            compTargetScope.IncludeDownstreamComputerTargets = true;
            compTargetScope.IncludeSubgroups = true;

            //get Update
            IUpdate update = UpdateServer.GetUpdate(updateID);
            UpdateInstallationInfoCollection updtCol = update.GetUpdateInstallationInfoPerComputerTarget(compTargetScope);

            foreach (IUpdateInstallationInfo clientStatus in updtCol)
            {
                Boolean addRow = true;

                IComputerTarget compTarget = UpdateServer.GetComputerTarget(clientStatus.ComputerTargetId);

                if (addRow)
                {
                    data.Rows.Add(compTarget.FullDomainName, compTarget.OSDescription + ", " + compTarget.OSArchitecture, compTarget.LastReportedStatusTime.ToString("yyy/MM/dd - HH:mm"), clientStatus.UpdateInstallationState.ToString());
                }
            }

            return data;
        }
        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);
            }
        }