コード例 #1
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// performs a specific run set
        /// </summary>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="runSet">
        /// A specific run set
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void DoRunSet(IUpdateServer server, RunSet runSet, bool isTest)
        {
            Console.WriteLine("Performing Run Set: " + runSet.Name);

            // get the target group rules
            Configuration.CheckIsValidRunSet(server, runSet);

            var alreadyProcessed = new List <IComputerTargetGroup>();

            if (runSet.TargetGroups.ElementInformation.IsPresent)
            {
                Console.WriteLine("Target Groups specified in Run Set.");
                TargetGroupCollection targetGroups = runSet.TargetGroups;
                foreach (TargetGroup targetGroup in targetGroups)
                {
                    DoRunSetTargetGroup(server, targetGroup, isTest, alreadyProcessed);
                }
            }
            else if (runSet.AllTargetGroups.ElementInformation.IsPresent)
            {
                AllTargetGroups allTargetGroups = runSet.AllTargetGroups;
                DoRunSetAllTargetGroups(server, allTargetGroups, isTest, alreadyProcessed);
            }
            else
            {
                throw new ConfigurationErrorsException(
                          "Couldn't find a \"targetGroup\" or \"allTargetGroups\" element in the runset.");
            }
        }
コード例 #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);
                }
            }
        }
コード例 #3
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
        private List <Dictionary <string, string> > GetUpdates(IUpdateServer wsus, string name = "")
        {
            List <Dictionary <string, string> > retList = new List <Dictionary <string, string> >();
            UpdateCollection updates = new UpdateCollection();

            if (name == "")
            {
                updates = wsus.GetUpdates();
            }
            else
            {
                updates = wsus.SearchUpdates(name);
            }
            foreach (IUpdate update in updates)
            {
                if (update.Description == "Carteiro Update Package")
                {
                    Dictionary <string, string> details = new Dictionary <string, string>();
                    details.Add("Id", update.Id.UpdateId.ToString());
                    details.Add("Title", update.Title);
                    details.Add("Description", update.Description.Trim());
                    details.Add("CreationDate", update.CreationDate.ToString());
                    details.Add("IsApproved", update.IsApproved.ToString());
                    details.Add("IsDeclined", update.IsDeclined.ToString());
                    retList.Add(details);
                }
            }
            return(retList);
        }
コード例 #4
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// Gets a list of update categories by searching for the guids specified in the config
        /// </summary>
        /// <param name="server">
        /// wsus server connection
        /// </param>
        /// <param name="products">
        /// list of product guids from config
        /// </param>
        /// <returns>
        /// collection of update categories
        /// </returns>
        private static UpdateCategoryCollection GetUpdateCategoryCollection(
            IUpdateServer server,
            ProductCollection products)
        {
            if (products == null)
            {
                throw new ArgumentNullException("products");
            }

            if (products.Count < 1)
            {
                throw new ArgumentException("products has no product items.");
            }

            var result = new UpdateCategoryCollection();

            foreach (Product product in products)
            {
                IUpdateCategory category = server.GetUpdateCategory(product.Guid);

                result.Add(category);
            }

            return(result);
        }
コード例 #5
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// Checks a classification for needed updates
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <param name="classification">
        /// a single update classification
        /// </param>
        /// <param name="rootGroup">
        /// the "all computers" group
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void CheckClassification(
            IUpdateServer server,
            IUpdateClassification classification,
            IComputerTargetGroup rootGroup,
            bool isTest,
            List <IComputerTargetGroup> alreadyProcessed)
        {
            Console.Out.WriteLine("Getting list of updates for : " + classification.Title);

            var searchScope = new UpdateScope {
                IncludedInstallationStates = UpdateInstallationStates.NotInstalled
            };

            searchScope.Classifications.Add(classification);
            UpdateCollection updates = server.GetUpdates(searchScope);

            if (updates.Count > 0)
            {
                DoClassificationUpdates(updates, rootGroup, isTest, alreadyProcessed);
            }
            else
            {
                Console.Out.WriteLine(" No updates required.");
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            //Create IUpdateServer variable and connect to WSUS Server

            //replace the "REPLACETHIS" with your WSUS Server Name, SSL or NOT, and Port. Syntax here is (SERVERNAME, REQUIRESSL, PORT)
            IUpdateServer server = AdminProxy.GetUpdateServer("REPLACETHIS", true, 443);

            //Begin loop thru updates and filter updates to just unapproved updates from beginning of time to current time
            foreach (IUpdate update in server.GetUpdates(ApprovedStates.NotApproved, DateTime.MinValue, DateTime.MaxValue, null, null))
            {
                //Convert UpdateType to string for comparison in following if statement
                string updatetype = update.UpdateType.ToString();

                //Filter for driver updates only
                if (updatetype == "Driver")
                {
                    //Write update name to console
                    Console.WriteLine("Declining update {0}", update.Title);
                    //Decline driver update
                    update.Decline();
                    //Write confimation to console
                    Console.WriteLine("Update Successfully Declined");
                }
            }


            //Wait at end of program
            string strWaitText = Environment.NewLine + "Press return to close";

            Console.WriteLine(strWaitText);
            Console.ReadLine();
        }
コード例 #7
0
ファイル: clsWSUS.cs プロジェクト: rjch-au/WSUSAdminAssistant
        public clsWSUS(clsConfig configobject)
        {
            cfg = configobject;

            // Initialise SQL query
            sql.ConnectionString = cfg.SQLConnectionString();

            if (CheckDBConnection())
            {
                // Set connection to SQL server for all queries
                cmdLastUpdate.Connection          = sql;
                cmdApprovedUpdates.Connection     = sql;
                cmdLastSync.Connection            = sql;
                cmdUnassignedComputers.Connection = sql;
                cmdUpdateErrors.Connection        = sql;
                cmdComputerGroups.Connection      = sql;
            }

            // Connect to WSUS server
            try
            {
                server     = AdminProxy.GetUpdateServer(cfg.WSUSServer, cfg.WSUSSecureConnection);
                wsusStatus = "OK";
            }
            catch (Exception ex)
            {
                wsusStatus = "Error: " + ex.Message;
            }
        }
コード例 #8
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// The do run set target group.
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <param name="targetGroup">
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetTargetGroup(
            IUpdateServer server,
            TargetGroup targetGroup,
            bool isTest,
            List <IComputerTargetGroup> alreadyProcessed)
        {
            Console.WriteLine("Processing Target Groups: " + targetGroup.Guid);

            // check the target group exists on wsus
            IComputerTargetGroup ctg = server.GetComputerTargetGroup(targetGroup.Guid);

            Console.WriteLine("Matched target group guid to: " + ctg.Name);

            // Get classifications
            if (targetGroup.Classifications.ElementInformation.IsPresent)
            {
                Console.WriteLine("Found a collection of specific classifications to apply.");
                DoRunSetClassifications(server, ctg, targetGroup.Classifications, isTest, alreadyProcessed);
            }
            else if (targetGroup.AllClassifications.ElementInformation.IsPresent)
            {
                Console.WriteLine("Applying all classifications.");
                DoRunSetAllClassifications(server, ctg, isTest, targetGroup.AllClassifications);
            }
            else
            {
                throw new ConfigurationErrorsException(
                          "Unable to detect if we are running a specific set of classifications, or processing all classifications");
            }
        }
コード例 #9
0
ファイル: Server.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// Gets the "All Computers" group
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <returns></returns>
        public static IComputerTargetGroup GetRootTargetGroup(IUpdateServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            return server.GetComputerTargetGroup(Microsoft.UpdateServices.Administration.ComputerTargetGroupId.AllComputers);
        }
コード例 #10
0
ファイル: Server.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// Gets the "All Computers" group
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <returns></returns>
        public static IComputerTargetGroup GetRootTargetGroup(IUpdateServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            return(server.GetComputerTargetGroup(Microsoft.UpdateServices.Administration.ComputerTargetGroupId.AllComputers));
        }
コード例 #11
0
ファイル: Server.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// Gets a list of product categories from WSUS
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <returns>
        /// Object representing the list of product categories
        /// </returns>
        public static UpdateCategoryCollection GetRootUpdateCategories(IUpdateServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            return server.GetRootUpdateCategories();
        }
コード例 #12
0
ファイル: Server.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// Gets a list of product categories from WSUS
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <returns>
        /// Object representing the list of product categories
        /// </returns>
        public static UpdateCategoryCollection GetRootUpdateCategories(IUpdateServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            return(server.GetRootUpdateCategories());
        }
コード例 #13
0
ファイル: Server.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// Gets the list of update classifications from WSUS
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <returns>
        /// Object representing the list of classifications
        /// </returns>
        public static UpdateClassificationCollection GetUpdateClassifications(IUpdateServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            return(server.GetUpdateClassifications());
        }
コード例 #14
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// checks for superseded updates and approves the new revision
        /// </summary>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="approveLicenseAgreement">
        /// Whether to approve any license agreement
        /// </param>
        /// <param name="computerTargetGroup">
        /// The target group to check
        /// </param>
        /// <param name="classification">
        /// Classification to process
        /// </param>
        /// <param name="products">
        /// Collection of products to process
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="shouldApproveUninstalledSupersededUpdate">
        /// The should Approve Uninstalled Superseded Update.
        /// </param>
        private static void CheckSupersededUpdates(
            IUpdateServer server,
            bool approveLicenseAgreement,
            IComputerTargetGroup computerTargetGroup,
            IUpdateClassification classification,
            UpdateCategoryCollection products,
            bool isTest,
            bool shouldApproveUninstalledSupersededUpdate)
        {
            var searchScope = new UpdateScope {
                ApprovedStates = ApprovedStates.HasStaleUpdateApprovals
            };

            if (computerTargetGroup != null)
            {
                searchScope.ApprovedComputerTargetGroups.Add(computerTargetGroup);
            }

            if (classification != null)
            {
                searchScope.Classifications.Add(classification);
            }

            if (products != null)
            {
                searchScope.Categories.AddRange(products);
            }

            UpdateCollection updates = server.GetUpdates(searchScope);

            if (updates.Count <= 0)
            {
                return;
            }

            var recentlyApproved = new List <Guid>();

            if (updates.Count == 0)
            {
                Console.Out.WriteLine(" No updates required.");
                return;
            }

            foreach (IUpdate update in updates)
            {
                if (update.IsSuperseded)
                {
                    CheckSupersededUpdate(
                        update,
                        approveLicenseAgreement,
                        isTest,
                        recentlyApproved,
                        shouldApproveUninstalledSupersededUpdate);
                }
            }
        }
コード例 #15
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /*
         * static void DoRunSetClassifications(
         *  Microsoft.UpdateServices.Administration.IUpdateServer server,
         *  Microsoft.UpdateServices.Administration.IComputerTargetGroup ctg,
         *  bool isTest,
         *  System.Collections.Generic.List<Microsoft.UpdateServices.Administration.IComputerTargetGroup> alreadyProcessed
         *  )
         * {
         *  //Model.ClassificationCollection classifications,
         *  Microsoft.UpdateServices.Administration.UpdateClassificationCollection classifications
         *      =server.GetUpdateClassifications();
         *  foreach (Model.Classification classification in classifications)
         *  {
         *      DoRunSetClassification(server, ctg, classification, isTest, alreadyProcessed);
         *  }
         * }
         * */

        /// <summary>
        /// The do run set classifications.
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <param name="computerTargetGroup">
        /// The target group to check
        /// </param>
        /// <param name="classifications">
        /// Collection of Classifications to process
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetClassifications(
            IUpdateServer server,
            IComputerTargetGroup computerTargetGroup,
            ClassificationCollection classifications,
            bool isTest,
            List <IComputerTargetGroup> alreadyProcessed)
        {
            foreach (Classification classification in classifications)
            {
                DoRunSetClassification(server, computerTargetGroup, classification, isTest, alreadyProcessed);
            }
        }
コード例 #16
0
 /// <summary>
 /// Connect to the Wsus Server and define the Preferred Culture.
 /// </summary>
 private void Connect()
 {
     if (this.WsusTarget.IsLocal)
     {
         this._updateServer = AdminProxy.GetUpdateServer();
     }
     else
     {
         this._updateServer = AdminProxy.GetUpdateServer(this.WsusTarget.ServerName, this.WsusTarget.UseSSL, this.WsusTarget.ServerPort);
         _timer.Interval    = _keepAliveInterval;
         _timer.Tick       += new EventHandler(_timer_Tick);
         _timer.Start();
     }
 }
コード例 #17
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            // Try to connect to SQL database
            string sqlconnect;

            if (chkIntegratedSecurity.Checked)
            {
                sqlconnect = "database=" + txtDB.Text + "; server=" + txtSQL.Text + ";Trusted_Connection=true";
            }
            else
            {
                sqlconnect = "database=" + txtDB.Text + "; server=" + txtSQL.Text + ";" + "User ID=" + txtUser.Text + ";Password="******"Could not connect to SQL database", MessageBoxButtons.OK);
                return;
            }

            // SQL seems good, check WSUS
            try
            {
                IUpdateServer wsus = AdminProxy.GetUpdateServer(txtWSUS.Text, chkSecure.Checked);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Could not connect to WSUS server", MessageBoxButtons.OK);
                return;
            }

            // Both are good, write configuration and restart program.
            cfg.DBServer             = txtWSUS.Text;
            cfg.DBDatabase           = txtDB.Text;
            cfg.DBUsername           = txtUser.Text;
            cfg.DBPassword           = txtPassword.Text;
            cfg.DBIntegratedAuth     = chkIntegratedSecurity.Checked;
            cfg.WSUSServer           = txtWSUS.Text;
            cfg.WSUSSecureConnection = chkSecure.Checked;

            Application.Restart();
        }
コード例 #18
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
        //private void CreateUpdateMsi()
        //{
        //    Project project =
        //     new Project("Foobar",

        //         new PathFileAction(
        //                     @"%WindowsFolder%\notepad.exe",
        //                     "readme.txt",
        //                     "INSTALLDIR",
        //                     Return.asyncNoWait,
        //                     When.After,
        //                     Step.InstallFinalize,
        //                     new Condition("(NOT Installed) AND (UILevel > 3)")) //execute this action during the installation but only if it is not silent mode (UILevel > 3)
        //     );

        //    project.GUID = new Guid("6f330b47-2577-43ad-9095-1861ba25889b");
        //    project.SourceBaseDir = Environment.CurrentDirectory;
        //    project.OutFileName = "setup";

        //    Compiler.WixLocation = ((string)Registry.GetValue(REG_PATH, "Path", null) + "CarteiroWin\\bin\\");
        //    Compiler.BuildMsi(project);
        //}

        //WSUS Group-Management
        private List <Dictionary <string, string> > GetComputerTargetGroups(IUpdateServer wsus)
        {
            List <Dictionary <string, string> > retList = new List <Dictionary <string, string> >();
            ComputerTargetGroupCollection       groups  = new ComputerTargetGroupCollection();

            groups = wsus.GetComputerTargetGroups();
            foreach (IComputerTargetGroup group in groups)
            {
                Dictionary <string, string> details = new Dictionary <string, string>();
                details.Add("Id", group.Id.ToString());
                details.Add("Name", group.Name);
                retList.Add(details);
            }
            return(retList);
        }
コード例 #19
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// The check needed updates.
        /// </summary>
        /// <param name="server">
        /// </param>
        /// <param name="ctg">
        /// </param>
        /// <param name="isTest">
        /// </param>
        private static void CheckNeededUpdates(
            IUpdateServer server,
            IComputerTargetGroup ctg,
            // Microsoft.UpdateServices.Administration.UpdateCategoryCollection products,
            bool isTest)
        {
            // check classifications
            Console.Out.WriteLine("Getting classifications");
            UpdateClassificationCollection classifications = Server.GetUpdateClassifications(server);

            // check for updates
            foreach (IUpdateClassification classification in classifications)
            {
                CheckClassification(server, classification, ctg, isTest, null);
            }
        }
コード例 #20
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
        private Dictionary <string, string> GetComputerTargetStatus(IUpdateServer wsus, string id)
        {
            Dictionary <string, string> retDict = new Dictionary <string, string>();
            IComputerTarget             target  = wsus.GetComputerTarget(id);
            IUpdateSummary summary = target.GetUpdateInstallationSummary();

            retDict.Add("InstalledCount", summary.InstalledCount.ToString());
            retDict.Add("DownloadedCount", summary.DownloadedCount.ToString());
            retDict.Add("FailedCount", summary.FailedCount.ToString());
            retDict.Add("InstalledPendingRebootCount", summary.InstalledPendingRebootCount.ToString());
            retDict.Add("IsSummedAcrossAllUpdates", summary.IsSummedAcrossAllUpdates.ToString());
            retDict.Add("LastUpdated", summary.LastUpdated.ToString());
            retDict.Add("NotApplicableCount", summary.NotApplicableCount.ToString());
            retDict.Add("UnknownCount", summary.UnknownCount.ToString());
            retDict.Add("NotInstalledCount", summary.NotInstalledCount.ToString());
            return(retDict);
        }
コード例 #21
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);
        }
コード例 #22
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         if (isLocal)
         {
             updateServer = adminProxy.GetUpdateServerInstance();
         }
         else
         {
             updateServer = adminProxy.GetRemoteUpdateServerInstance(wuaServer, UseSecureConnection, portNumber);
         }
     }
     catch
     {
     }
 }
コード例 #23
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
        private List <Dictionary <string, string> > GetComputerTargetGroup(IUpdateServer wsus, string id)
        {
            List <Dictionary <string, string> > retList = new List <Dictionary <string, string> >();
            IComputerTargetGroup     group   = wsus.GetComputerTargetGroup(new Guid(id));
            ComputerTargetCollection members = group.GetComputerTargets();

            foreach (IComputerTarget member in members)
            {
                Dictionary <string, string> details = new Dictionary <string, string>();
                details.Add("Id", member.Id);
                details.Add("Name", member.FullDomainName);
                details.Add("Ip", member.IPAddress.ToString());
                details.Add("LastReport", member.LastReportedInventoryTime.ToString());
                details.Add("ComputerRole", member.ComputerRole.ToString());

                retList.Add(details);
            }
            return(retList);
        }
コード例 #24
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
        private static IUpdateServer ConnectLocal()
        {
            string dnsName = (string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\bitformerGmbH\\CarteiroWin",
                                                       "DnsServerName",
                                                       Environment.MachineName);

            try
            {
                IUpdateServer wsus = AdminProxy.GetUpdateServer(dnsName, true, 8531);
                return(wsus);
            }
            catch (Exception)
            {
                Console.Error.WriteLine("Try to unsafe connect to " + Environment.MachineName);
                IUpdateServer wsus = AdminProxy.GetUpdateServer(Environment.MachineName, false, 8530);
                Console.Error.WriteLine("WARNING: SSL Connection could not been established, connection is unsafe");
                return(wsus);
            }
        }
コード例 #25
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// The do run set all classifications.
        /// </summary>
        /// <param name="server">
        /// The server.
        /// </param>
        /// <param name="ctg">
        /// The ctg.
        /// </param>
        /// <param name="isTest">
        /// The is Test.
        /// </param>
        /// <param name="allClassifications">
        /// The all Classifications.
        /// </param>
        private static void DoRunSetAllClassifications(
            IUpdateServer server,
            IComputerTargetGroup ctg,
            bool isTest,
            Rule allClassifications)
        {
            // TODO: support products in all classifications element
            // Microsoft.UpdateServices.Administration.UpdateCategoryCollection products = null;
            if (allClassifications.Copy)
            {
                // Check for copy
                Console.Out.WriteLine("Checking TargetGroup to Copy From: ");
                IComputerTargetGroup cftg = server.GetComputerTargetGroup(allClassifications.CopyFrom);
                Console.WriteLine("Matched copy from guid to: " + cftg.Name);
                CopyFrom.DoCopy(server, cftg, ctg, isTest);
            }

            if (allClassifications.ApproveSupersededUpdates)
            {
                // Check for superseded updates
                Console.Out.WriteLine("Checking Superseded Updates: ");
                CheckSupersededUpdates(
                    server,
                    allClassifications.AcceptLicenseAgreement,
                    ctg,
                    null,
                    null,
                    isTest,
                    allClassifications.ShouldApproveUninstalledSupersededUpdate);
            }

            if (allClassifications.ApproveStaleUpdates)
            {
                // Check for stale updates
                Console.Out.WriteLine("Checking Stale Updates: ");
                CheckStaleUpdates(server, allClassifications.AcceptLicenseAgreement, ctg, null, null, isTest);
            }

            if (allClassifications.ApproveNeededUpdates)
            {
                CheckNeededUpdates(server, ctg, isTest);
            }
        }
コード例 #26
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// The do run set classification.
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <param name="computerTargetGroup">
        /// The target group to check
        /// </param>
        /// <param name="classification">
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetClassification(
            IUpdateServer server,
            IComputerTargetGroup computerTargetGroup,
            Classification classification,
            bool isTest,
            List <IComputerTargetGroup> alreadyProcessed)
        {
            // check the classification exists on wsus
            IUpdateClassification uc = server.GetUpdateClassification(classification.Guid);

            // check for a product collection
            UpdateCategoryCollection products = classification.Products.ElementInformation.IsPresent
                                                    ? GetUpdateCategoryCollection(server, classification.Products)
                                                    : null;

            if (classification.ApproveStaleUpdates)
            {
                CheckStaleUpdates(
                    server,
                    classification.AcceptLicenseAgreement,
                    computerTargetGroup,
                    uc,
                    products,
                    isTest);
            }

            if (classification.ApproveSupersededUpdates)
            {
                CheckSupersededUpdates(
                    server,
                    classification.AcceptLicenseAgreement,
                    computerTargetGroup,
                    uc,
                    products,
                    isTest,
                    classification.ShouldApproveUninstalledSupersededUpdate);
            }

            if (classification.ApproveNeededUpdates)
            {
                CheckClassification(server, uc, computerTargetGroup, isTest, alreadyProcessed);
            }
        }
コード例 #27
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// The do run set all target groups.
        /// </summary>
        /// <param name="server">
        /// </param>
        /// <param name="allTargetGroups">
        /// </param>
        /// <param name="isTest">
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetAllTargetGroups(
            IUpdateServer server,
            AllTargetGroups allTargetGroups,
            bool isTest,
            List <IComputerTargetGroup> alreadyProcessed)
        {
            Console.Out.WriteLine("Getting root target group: ");
            IComputerTargetGroup rootGroup = Server.GetRootTargetGroup(server);

            ClassificationCollection classifications = allTargetGroups.Classifications;

            if (classifications.Count > 0)
            {
                DoRunSetClassifications(server, rootGroup, classifications, isTest, alreadyProcessed);
            }
            else
            {
                DoRunSetAllClassifications(server, rootGroup, isTest, allTargetGroups.AllClassifications);
            }
        }
コード例 #28
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// Checks for updates that may have a new revision
        /// </summary>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="approveLicenseAgreement">
        /// Whether to approve any license agreement
        /// </param>
        /// <param name="computerTargetGroup">
        /// The target group to check
        /// </param>
        /// <param name="classifications">
        /// Classification to process
        /// </param>
        /// <param name="products">
        /// Collection of products to process
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void CheckStaleUpdates(
            IUpdateServer server,
            bool approveLicenseAgreement,
            IComputerTargetGroup computerTargetGroup,
            IUpdateClassification classifications,
            UpdateCategoryCollection products,
            bool isTest)
        {
            var searchScope = new UpdateScope {
                ApprovedStates = ApprovedStates.HasStaleUpdateApprovals
            };

            if (computerTargetGroup != null)
            {
                searchScope.ApprovedComputerTargetGroups.Add(computerTargetGroup);
            }

            if (classifications != null)
            {
                searchScope.Classifications.Add(classifications);
            }

            if (products != null)
            {
                searchScope.Categories.AddRange(products);
            }

            UpdateCollection updates = server.GetUpdates(searchScope);

            if (updates.Count > 0)
            {
                foreach (IUpdate update in updates)
                {
                    CheckStaleUpdate(update, isTest, approveLicenseAgreement);
                }
            }
            else
            {
                Console.Out.WriteLine(" No updates required.");
            }
        }
コード例 #29
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
 private static void SetWsusCertificate(string certPath, string certPass, IUpdateServer wServ)
 {
     if (wServ.IsConnectionSecureForApiRemoting)
     {
         try
         {
             var wsusConf = wServ.GetConfiguration();
             wsusConf.SetSigningCertificate(certPath, certPass);
             wsusConf.Save();
             Console.WriteLine("INFO: new Certificate imported");
         }
         catch (Exception e)
         {
             Console.Error.WriteLine("ERROR: " + e.Message);
         }
     }
     else
     {
         Console.Error.WriteLine("ERROR: this operation is not possible with an unsafe connection");
     }
 }
コード例 #30
0
        public static void PopulateUpdateResults(IUpdateServer server, UpdateResults resultobject)
        {
            Console.WriteLine("Reading update information. This may take several minutes. Please wait...");
            List <UpdateCollection> collections = new List <UpdateCollection>();
            var approvedstates = Enum.GetValues(typeof(ApprovedStates));

            //This breaks the query up. If we use a straight GetUpdates() it is likely to timeout. This
            //allows the query to be filtered to give more control.
            foreach (IUpdateClassification classification in server.GetUpdateClassifications())
            {
                //Drivers cause timeouts so we skip them
                if (classification.Title == "Drivers")
                {
                    continue;
                }
                Console.Write("Processing " + classification.Title);
                UpdateClassificationCollection classcol = new UpdateClassificationCollection();
                classcol.Add(classification);
                foreach (ApprovedStates state in approvedstates)
                {
                    //Console.WriteLine(state);
                    Console.Write(".");
                    collections.Add(server.GetUpdates(state, DateTime.MinValue, DateTime.MaxValue, null, classcol));
                }
                Console.WriteLine();
            }

            foreach (UpdateCollection col in collections)
            {
                foreach (IUpdate update in col)
                {
                    resultobject.Updates.Add(Update.GetUpdateObject(update));
                    if (update.IsSuperseded)
                    {
                        List <object> supersededmappings = GetRelatedUpdates(update, UpdateRelationship.UpdatesThatSupersedeThisUpdate);
                        resultobject.SupersededUpdates.AddRange(supersededmappings);
                    }
                }
            }
        }
コード例 #31
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
        private static void SetWsusCertificate(IUpdateServer wServ)
        {
            //Self Signed Certifications creation by WSUS server is deprecated, need an workaround
            if (wServ.IsConnectionSecureForApiRemoting)
            {
                try
                {
                    String           secret = "Secure!";
                    X509Certificate2 cert   = CreateSelfSignedCertificate("Carteiro");
                    File.WriteAllBytes("C:\\carteiro.pfx", cert.Export(X509ContentType.Pfx, secret));
                    File.WriteAllBytes("C:\\carteiro.cer", cert.Export(X509ContentType.Cert));
                    SetWsusCertificate("C:\\carteiro.pfx", secret, wServ);

                    //Importing into other stores
                    System.Security.Cryptography.X509Certificates.X509Store authRootStore         = new System.Security.Cryptography.X509Certificates.X509Store("AuthRoot", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine);
                    System.Security.Cryptography.X509Certificates.X509Store trustedPublisherStore = new System.Security.Cryptography.X509Certificates.X509Store("TrustedPublisher", System.Security.Cryptography.X509Certificates.StoreLocation.LocalMachine);

                    authRootStore.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadWrite);
                    trustedPublisherStore.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadWrite);

                    authRootStore.Add(cert);
                    trustedPublisherStore.Add(cert);

                    authRootStore.Close();
                    trustedPublisherStore.Close();

                    Console.WriteLine("INFO: certificates were succesfully imported into AuthRoot and Trusted Publisher stores");
                    Console.WriteLine("INFO: setting new WSUS Certificate finished!");
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine("ERROR: " + e.Message);
                }
            }
            else
            {
                Console.Error.WriteLine("ERROR: this operation is not possible with an unsafe connection");
            }
        }
コード例 #32
0
ファイル: Job.cs プロジェクト: WinnME/wsussmartapprove
        /// <summary>
        /// This is the path run if there are no run sets in the app.config
        ///     This is the classic apply to all groups approach from 1.0.0.0
        /// </summary>
        /// <param name="settings">
        /// application settings
        /// </param>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void DoNoRunSets(ApplicationSettings settings, IUpdateServer server, bool isTest)
        {
            Console.WriteLine("Performing \"No Run Set\" rule: ");

            // Get target groups
            Console.Out.WriteLine("Getting root target group: ");
            IComputerTargetGroup rootGroup = Server.GetRootTargetGroup(server);

            Console.Out.WriteLine("succeeded.");

            Rule defaultRule = settings.NoRunSet;

            if (defaultRule.ApproveSupersededUpdates)
            {
                // Check for superseded updates
                Console.Out.WriteLine("Checking Superseded Updates: ");
                CheckSupersededUpdates(
                    server,
                    defaultRule.AcceptLicenseAgreement,
                    null,
                    null,
                    null,
                    isTest,
                    defaultRule.ShouldApproveUninstalledSupersededUpdate);
            }

            if (defaultRule.ApproveStaleUpdates)
            {
                // Check for stale updates
                Console.Out.WriteLine("Checking Stale Updates: ");
                CheckStaleUpdates(server, defaultRule.AcceptLicenseAgreement, null, null, null, isTest);
            }

            if (defaultRule.ApproveNeededUpdates)
            {
                CheckNeededUpdates(server, rootGroup, isTest);
            }
        }
コード例 #33
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// Gets a list of update categories by searching for the guids specified in the config
        /// </summary>
        /// <param name="server">
        /// wsus server connection
        /// </param>
        /// <param name="products">
        /// list of product guids from config
        /// </param>
        /// <returns>
        /// collection of update categories
        /// </returns>
        private static UpdateCategoryCollection GetUpdateCategoryCollection(
            IUpdateServer server,
            ProductCollection products)
        {
            if (products == null)
            {
                throw new ArgumentNullException("products");
            }

            if (products.Count < 1)
            {
                throw new ArgumentException("products has no product items.");
            }

            var result = new UpdateCategoryCollection();

            foreach (Product product in products)
            {
                IUpdateCategory category = server.GetUpdateCategory(product.Guid);

                result.Add(category);
            }

            return result;
        }
コード例 #34
0
ファイル: frmMain.cs プロジェクト: rjch-au/WSUSAdminAssistant
 public void SetUpstreamServerByGuid(object g, IUpdateServer wsus)
 {
     // If the object is a database null, it's the local server
     if (g is DBNull)
         _UpstreamServer = "Local";
     else
     {
         try
         {
             _UpstreamServer = wsus.GetDownstreamServer((Guid) g).FullDomainName;
         }
         catch (Exception e)
         {
             _UpstreamServer = e.Message + ", GUID: " + g.ToString();
         }
     }
 }
コード例 #35
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// The do run set classification.
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <param name="computerTargetGroup">
        /// The target group to check
        /// </param>
        /// <param name="classification">
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetClassification(
            IUpdateServer server,
            IComputerTargetGroup computerTargetGroup,
            Classification classification,
            bool isTest,
            List<IComputerTargetGroup> alreadyProcessed)
        {
            // check the classification exists on wsus
            IUpdateClassification uc = server.GetUpdateClassification(classification.Guid);

            // check for a product collection
            UpdateCategoryCollection products = classification.Products.ElementInformation.IsPresent
                                                    ? GetUpdateCategoryCollection(server, classification.Products)
                                                    : null;

            if (classification.ApproveStaleUpdates)
            {
                CheckStaleUpdates(
                    server,
                    classification.AcceptLicenseAgreement,
                    computerTargetGroup,
                    uc,
                    products,
                    isTest);
            }

            if (classification.ApproveSupersededUpdates)
            {
                CheckSupersededUpdates(
                    server,
                    classification.AcceptLicenseAgreement,
                    computerTargetGroup,
                    uc,
                    products,
                    isTest,
                    classification.ShouldApproveUninstalledSupersededUpdate);
            }

            if (classification.ApproveNeededUpdates)
            {
                CheckClassification(server, uc, computerTargetGroup, isTest, alreadyProcessed);
            }
        }
コード例 #36
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// This is run when there are a group of runsets in the app.config
        ///     Run Sets allow for different options to be run on different occasions
        ///     The runset is specified on the command line
        /// </summary>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="runSets">
        /// Group of runsets
        /// </param>
        /// <param name="commandLine">
        /// Information on what was specified on the command line
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void DoRunSets(
            // Model.ApplicationSettings settings,
            IUpdateServer server,
            RunSetCollection runSets,
            CommandLine commandLine,
            bool isTest)
        {
            // we need to work out which runset is being done
            // we'll limit the command line to one runset
            string requestedRunSet = commandLine.GetRunSetName();

            RunSet requiredRunSet =
                runSets.Cast<RunSet>()
                    .FirstOrDefault(runSet => requestedRunSet.Equals(runSet.Name, StringComparison.OrdinalIgnoreCase));

            if (requiredRunSet == null)
            {
                throw new ArgumentException(
                    "The RunSet '" + requestedRunSet
                    + "' as requested on the command line is not defined in the app.config.");
            }

            DoRunSet(server, requiredRunSet, isTest);
        }
コード例 #37
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// This is the path run if there are no run sets in the app.config
        ///     This is the classic apply to all groups approach from 1.0.0.0
        /// </summary>
        /// <param name="settings">
        /// application settings
        /// </param>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void DoNoRunSets(ApplicationSettings settings, IUpdateServer server, bool isTest)
        {
            Console.WriteLine("Performing \"No Run Set\" rule: ");

            // Get target groups
            Console.Out.WriteLine("Getting root target group: ");
            IComputerTargetGroup rootGroup = Server.GetRootTargetGroup(server);
            Console.Out.WriteLine("succeeded.");

            Rule defaultRule = settings.NoRunSet;

            if (defaultRule.ApproveSupersededUpdates)
            {
                // Check for superseded updates
                Console.Out.WriteLine("Checking Superseded Updates: ");
                CheckSupersededUpdates(
                    server,
                    defaultRule.AcceptLicenseAgreement,
                    null,
                    null,
                    null,
                    isTest,
                    defaultRule.ShouldApproveUninstalledSupersededUpdate);
            }

            if (defaultRule.ApproveStaleUpdates)
            {
                // Check for stale updates
                Console.Out.WriteLine("Checking Stale Updates: ");
                CheckStaleUpdates(server, defaultRule.AcceptLicenseAgreement, null, null, null, isTest);
            }

            if (defaultRule.ApproveNeededUpdates)
            {
                CheckNeededUpdates(server, rootGroup, isTest);
            }
        }
コード例 #38
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// The do run set all classifications.
        /// </summary>
        /// <param name="server">
        /// The server.
        /// </param>
        /// <param name="ctg">
        /// The ctg.
        /// </param>
        /// <param name="isTest">
        /// The is Test.
        /// </param>
        /// <param name="allClassifications">
        /// The all Classifications.
        /// </param>
        private static void DoRunSetAllClassifications(
            IUpdateServer server,
            IComputerTargetGroup ctg,
            bool isTest,
            Rule allClassifications)
        {
            // TODO: support products in all classifications element
            // Microsoft.UpdateServices.Administration.UpdateCategoryCollection products = null;
            if (allClassifications.Copy)
            {
                // Check for copy
                Console.Out.WriteLine("Checking TargetGroup to Copy From: ");
                IComputerTargetGroup cftg = server.GetComputerTargetGroup(allClassifications.CopyFrom);
                Console.WriteLine("Matched copy from guid to: " + cftg.Name);
                CopyFrom.DoCopy(server, cftg, ctg, isTest);
            }

            if (allClassifications.ApproveSupersededUpdates)
            {
                // Check for superseded updates
                Console.Out.WriteLine("Checking Superseded Updates: ");
                CheckSupersededUpdates(
                    server,
                    allClassifications.AcceptLicenseAgreement,
                    ctg,
                    null,
                    null,
                    isTest,
                    allClassifications.ShouldApproveUninstalledSupersededUpdate);
            }

            if (allClassifications.ApproveStaleUpdates)
            {
                // Check for stale updates
                Console.Out.WriteLine("Checking Stale Updates: ");
                CheckStaleUpdates(server, allClassifications.AcceptLicenseAgreement, ctg, null, null, isTest);
            }

            if (allClassifications.ApproveNeededUpdates)
            {
                CheckNeededUpdates(server, ctg, isTest);
            }
        }
コード例 #39
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// Checks for updates that may have a new revision
        /// </summary>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="approveLicenseAgreement">
        /// Whether to approve any license agreement
        /// </param>
        /// <param name="computerTargetGroup">
        /// The target group to check
        /// </param>
        /// <param name="classifications">
        /// Classification to process
        /// </param>
        /// <param name="products">
        /// Collection of products to process
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void CheckStaleUpdates(
            IUpdateServer server,
            bool approveLicenseAgreement,
            IComputerTargetGroup computerTargetGroup,
            IUpdateClassification classifications,
            UpdateCategoryCollection products,
            bool isTest)
        {
            var searchScope = new UpdateScope { ApprovedStates = ApprovedStates.HasStaleUpdateApprovals };

            if (computerTargetGroup != null)
            {
                searchScope.ApprovedComputerTargetGroups.Add(computerTargetGroup);
            }

            if (classifications != null)
            {
                searchScope.Classifications.Add(classifications);
            }

            if (products != null)
            {
                searchScope.Categories.AddRange(products);
            }

            UpdateCollection updates = server.GetUpdates(searchScope);

            if (updates.Count > 0)
            {
                foreach (IUpdate update in updates)
                {
                    CheckStaleUpdate(update, isTest, approveLicenseAgreement);
                }
            }
            else
            {
                Console.Out.WriteLine(" No updates required.");
            }
        }
コード例 #40
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// Checks a classification for needed updates
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <param name="classification">
        /// a single update classification
        /// </param>
        /// <param name="rootGroup">
        /// the "all computers" group
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void CheckClassification(
            IUpdateServer server,
            IUpdateClassification classification,
            IComputerTargetGroup rootGroup,
            bool isTest,
            List<IComputerTargetGroup> alreadyProcessed)
        {
            Console.Out.WriteLine("Getting list of updates for : " + classification.Title);

            var searchScope = new UpdateScope { IncludedInstallationStates = UpdateInstallationStates.NotInstalled };

            searchScope.Classifications.Add(classification);
            UpdateCollection updates = server.GetUpdates(searchScope);

            if (updates.Count > 0)
            {
                DoClassificationUpdates(updates, rootGroup, isTest, alreadyProcessed);
            }
            else
            {
                Console.Out.WriteLine(" No updates required.");
            }
        }
コード例 #41
0
ファイル: Server.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// Gets the list of update classifications from WSUS
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <returns>
        /// Object representing the list of classifications
        /// </returns>
        public static UpdateClassificationCollection GetUpdateClassifications(IUpdateServer server)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            return server.GetUpdateClassifications();
        }
コード例 #42
0
ファイル: clsWSUS.cs プロジェクト: rjch-au/WSUSAdminAssistant
        public clsWSUS()
        {
            // Initialise SQL query
            sql.ConnectionString = cfg.SQLConnectionString();

            if (CheckDBConnection())
            {
                // Set connection to SQL server for all queries
                cmdUnapproved.Connection = sql;
                cmdLastUpdate.Connection = sql;
                cmdApprovedUpdates.Connection = sql;
                cmdLastSync.Connection = sql;
                cmdUnassignedComputers.Connection = sql;
                cmdUpdateErrors.Connection = sql;
                cmdComputerGroups.Connection = sql;
            }

            // Connect to WSUS server
            try
            {
                server = AdminProxy.GetUpdateServer(cfg.WSUSServer, cfg.WSUSSecureConnection);
                wsusStatus = "OK";
            }
            catch (Exception ex)
            {
                wsusStatus = "Error: " + ex.Message;
            }
        }
コード例 #43
0
 public void Setup()
 {
     localStructureManager = MockRepository.GenerateStub<ILocalStructureManager>();
     updateServer = MockRepository.GenerateStub<IUpdateServer>();
     updaterChef = new UpdaterChef(localStructureManager, updateServer);
 }
コード例 #44
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// The check needed updates.
        /// </summary>
        /// <param name="server">
        /// </param>
        /// <param name="ctg">
        /// </param>
        /// <param name="isTest">
        /// </param>
        private static void CheckNeededUpdates(
            IUpdateServer server,
            IComputerTargetGroup ctg,
            // Microsoft.UpdateServices.Administration.UpdateCategoryCollection products,
            bool isTest)
        {
            // check classifications
            Console.Out.WriteLine("Getting classifications");
            UpdateClassificationCollection classifications = Server.GetUpdateClassifications(server);

            // check for updates
            foreach (IUpdateClassification classification in classifications)
            {
                CheckClassification(server, classification, ctg, isTest, null);
            }
        }
コード例 #45
0
 public UpdateManager(IUpdateServer updateServer, ILocalStructureManager localStructureManager, IUpdaterChef updaterChef)
 {
     this.updateServer = updateServer;
     this.localStructureManager = localStructureManager;
     this.updaterChef = updaterChef;
 }
コード例 #46
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// checks for superseded updates and approves the new revision
        /// </summary>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="approveLicenseAgreement">
        /// Whether to approve any license agreement
        /// </param>
        /// <param name="computerTargetGroup">
        /// The target group to check
        /// </param>
        /// <param name="classification">
        /// Classification to process
        /// </param>
        /// <param name="products">
        /// Collection of products to process
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="shouldApproveUninstalledSupersededUpdate">
        /// The should Approve Uninstalled Superseded Update.
        /// </param>
        private static void CheckSupersededUpdates(
            IUpdateServer server,
            bool approveLicenseAgreement,
            IComputerTargetGroup computerTargetGroup,
            IUpdateClassification classification,
            UpdateCategoryCollection products,
            bool isTest,
            bool shouldApproveUninstalledSupersededUpdate)
        {
            var searchScope = new UpdateScope { ApprovedStates = ApprovedStates.HasStaleUpdateApprovals };

            if (computerTargetGroup != null)
            {
                searchScope.ApprovedComputerTargetGroups.Add(computerTargetGroup);
            }

            if (classification != null)
            {
                searchScope.Classifications.Add(classification);
            }

            if (products != null)
            {
                searchScope.Categories.AddRange(products);
            }

            UpdateCollection updates = server.GetUpdates(searchScope);

            if (updates.Count <= 0)
            {
                return;
            }

            var recentlyApproved = new List<Guid>();

            if (updates.Count == 0)
            {
                Console.Out.WriteLine(" No updates required.");
                return;
            }

            foreach (IUpdate update in updates)
            {
                if (update.IsSuperseded)
                {
                    CheckSupersededUpdate(
                        update,
                        approveLicenseAgreement,
                        isTest,
                        recentlyApproved,
                        shouldApproveUninstalledSupersededUpdate);
                }
            }
        }
コード例 #47
0
ファイル: UpdaterChef.cs プロジェクト: diogomafra/AppUpdater
 public UpdaterChef(ILocalStructureManager localStructureManager, IUpdateServer updateServer)
 {
     this.localStructureManager = localStructureManager;
     this.updateServer = updateServer;
 }
コード例 #48
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// performs a specific run set
        /// </summary>
        /// <param name="server">
        /// The WSUS Server
        /// </param>
        /// <param name="runSet">
        /// A specific run set
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        private static void DoRunSet(IUpdateServer server, RunSet runSet, bool isTest)
        {
            Console.WriteLine("Performing Run Set: " + runSet.Name);

            // get the target group rules
            Configuration.CheckIsValidRunSet(server, runSet);

            var alreadyProcessed = new List<IComputerTargetGroup>();

            if (runSet.TargetGroups.ElementInformation.IsPresent)
            {
                Console.WriteLine("Target Groups specified in Run Set.");
                TargetGroupCollection targetGroups = runSet.TargetGroups;
                foreach (TargetGroup targetGroup in targetGroups)
                {
                    DoRunSetTargetGroup(server, targetGroup, isTest, alreadyProcessed);
                }
            }
            else if (runSet.AllTargetGroups.ElementInformation.IsPresent)
            {
                AllTargetGroups allTargetGroups = runSet.AllTargetGroups;
                DoRunSetAllTargetGroups(server, allTargetGroups, isTest, alreadyProcessed);
            }
            else
            {
                throw new ConfigurationErrorsException(
                    "Couldn't find a \"targetGroup\" or \"allTargetGroups\" element in the runset.");
            }
        }
コード例 #49
0
 protected override void ProcessRecord()
 {
     base.ProcessRecord();
     try
     {
         if (isLocal)
         {
             updateServer = adminProxy.GetUpdateServerInstance();
         }
         else
         {
             updateServer = adminProxy.GetRemoteUpdateServerInstance(wuaServer, UseSecureConnection, portNumber);
         }
     }
     catch
     {
     }
 }
コード例 #50
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// The do run set all target groups.
        /// </summary>
        /// <param name="server">
        /// </param>
        /// <param name="allTargetGroups">
        /// </param>
        /// <param name="isTest">
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetAllTargetGroups(
            IUpdateServer server,
            AllTargetGroups allTargetGroups,
            bool isTest,
            List<IComputerTargetGroup> alreadyProcessed)
        {
            Console.Out.WriteLine("Getting root target group: ");
            IComputerTargetGroup rootGroup = Server.GetRootTargetGroup(server);

            ClassificationCollection classifications = allTargetGroups.Classifications;
            if (classifications.Count > 0)
            {
                DoRunSetClassifications(server, rootGroup, classifications, isTest, alreadyProcessed);
            }
            else
            {
                DoRunSetAllClassifications(server, rootGroup, isTest, allTargetGroups.AllClassifications);
            }
        }
コード例 #51
0
            public void Setup()
            {
                updateServer = MockRepository.GenerateStub<IUpdateServer>();
                localStructureManager = MockRepository.GenerateStub<ILocalStructureManager>();
                updaterChef = MockRepository.GenerateStub<IUpdaterChef>();
                updateManager = new UpdateManager(updateServer, localStructureManager, updaterChef);

                initialVersion = "1.2.3";
                installedVersions = new string[] { "1.0.0", "1.1.1", "1.2.3" };
                localStructureManager.Stub(x => x.GetCurrentVersion()).Return(initialVersion);
                localStructureManager.Stub(x => x.GetExecutingVersion()).Return(initialVersion);
                localStructureManager.Stub(x => x.GetInstalledVersions()).Do(new Func<string[]>(()=>installedVersions));
                updateManager.Initialize();
            }
コード例 #52
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
 /*
 static void DoRunSetClassifications(
     Microsoft.UpdateServices.Administration.IUpdateServer server,
     Microsoft.UpdateServices.Administration.IComputerTargetGroup ctg,
     bool isTest,
     System.Collections.Generic.List<Microsoft.UpdateServices.Administration.IComputerTargetGroup> alreadyProcessed
     )
 {
     //Model.ClassificationCollection classifications,
     Microsoft.UpdateServices.Administration.UpdateClassificationCollection classifications
         =server.GetUpdateClassifications();
     foreach (Model.Classification classification in classifications)
     {
         DoRunSetClassification(server, ctg, classification, isTest, alreadyProcessed);
     }
 }
  * */
 /// <summary>
 /// The do run set classifications.
 /// </summary>
 /// <param name="server">
 /// Object representing the WSUS server
 /// </param>
 /// <param name="computerTargetGroup">
 /// The target group to check
 /// </param>
 /// <param name="classifications">
 /// Collection of Classifications to process
 /// </param>
 /// <param name="isTest">
 /// Whether we are in test mode
 /// </param>
 /// <param name="alreadyProcessed">
 /// List of target groups that have already been processed
 /// </param>
 private static void DoRunSetClassifications(
     IUpdateServer server,
     IComputerTargetGroup computerTargetGroup,
     ClassificationCollection classifications,
     bool isTest,
     List<IComputerTargetGroup> alreadyProcessed)
 {
     foreach (Classification classification in classifications)
     {
         DoRunSetClassification(server, computerTargetGroup, classification, isTest, alreadyProcessed);
     }
 }
コード例 #53
0
 public void Setup()
 {
     updateServer = MockRepository.GenerateStub<IUpdateServer>();
     localStructureManager = MockRepository.GenerateStub<ILocalStructureManager>();
     var updaterChef = MockRepository.GenerateStub<IUpdaterChef>();
     updateManager = new UpdateManager(updateServer, localStructureManager, updaterChef);
 }
コード例 #54
0
ファイル: Job.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// The do run set target group.
        /// </summary>
        /// <param name="server">
        /// Object representing the WSUS server
        /// </param>
        /// <param name="targetGroup">
        /// </param>
        /// <param name="isTest">
        /// Whether we are in test mode
        /// </param>
        /// <param name="alreadyProcessed">
        /// List of target groups that have already been processed
        /// </param>
        private static void DoRunSetTargetGroup(
            IUpdateServer server,
            TargetGroup targetGroup,
            bool isTest,
            List<IComputerTargetGroup> alreadyProcessed)
        {
            Console.WriteLine("Processing Target Groups: " + targetGroup.Guid);

            // check the target group exists on wsus
            IComputerTargetGroup ctg = server.GetComputerTargetGroup(targetGroup.Guid);

            Console.WriteLine("Matched target group guid to: " + ctg.Name);

            // Get classifications
            if (targetGroup.Classifications.ElementInformation.IsPresent)
            {
                Console.WriteLine("Found a collection of specific classifications to apply.");
                DoRunSetClassifications(server, ctg, targetGroup.Classifications, isTest, alreadyProcessed);
            }
            else if (targetGroup.AllClassifications.ElementInformation.IsPresent)
            {
                Console.WriteLine("Applying all classifications.");
                DoRunSetAllClassifications(server, ctg, isTest, targetGroup.AllClassifications);
            }
            else
            {
                throw new ConfigurationErrorsException(
                    "Unable to detect if we are running a specific set of classifications, or processing all classifications");
            }
        }
コード例 #55
0
ファイル: CopyFrom.cs プロジェクト: dpvreony/wsussmartapprove
        /// <summary>
        /// Entry point for copying approvals from one target group to another
        /// </summary>
        /// <param name="server">
        /// The server.
        /// </param>
        /// <param name="sourceGroup">
        /// The source group.
        /// </param>
        /// <param name="destinationGroup">
        /// The destination group.
        /// </param>
        /// <param name="isTest">
        /// Whether this is a test run.
        /// </param>
        public static void DoCopy(
            IUpdateServer server, IComputerTargetGroup sourceGroup, IComputerTargetGroup destinationGroup, bool isTest)
        {
            // get IComputerTargetGroup references for the source and destination groups
            if (isTest)
            {
                Console.Out.Write("(TEST) ");
            }

            Console.Out.WriteLine(
                "Copying update approvals from group {0} to group {1}.", sourceGroup.Name, destinationGroup.Name);

            // loop over all updates, copying approvals from the source group to the destination
            // group as necessary
            var updates = server.GetUpdates();

            foreach (IUpdate update in updates)
            {
                var sourceApprovals = update.GetUpdateApprovals(sourceGroup);
                var destinationApprovals = update.GetUpdateApprovals(destinationGroup);

                // for simplicity, this program assumes that an update has
                // at most one approval to a given group
                if (sourceApprovals.Count > 1)
                {
                    Console.Out.WriteLine(
                        "{0} had multiple approvals to group {1}; skipping.", update.Title, sourceGroup.Name);
                    continue;
                }

                if (destinationApprovals.Count > 1)
                {
                    Console.Out.WriteLine(
                        "{0} had multiple approvals to group {1}; skipping.", update.Title, destinationGroup.Name);
                    continue;
                }

                IUpdateApproval sourceApproval = null;
                IUpdateApproval destinationApproval = null;

                if (sourceApprovals.Count > 0)
                {
                    sourceApproval = sourceApprovals[0];
                }

                if (destinationApprovals.Count > 0)
                {
                    destinationApproval = destinationApprovals[0];
                }

                if (sourceApproval == null)
                {
                    // the update is not approved to the source group
                    if (destinationApproval != null)
                    {
                        // the update is not approved to the source group, but it is approved
                        // to the destination group
                        // unapprove the update for the destination group to match the source
                        Console.Out.WriteLine("Unapproving {0} to group {1}.", update.Title, destinationGroup.Name);
                        if (isTest)
                        {
                            Console.Out.Write("(TEST) ");
                        }
                        else
                        {
                            destinationApproval.Delete();
                        }
                    }

                    // neither the source group nor the destination group have an approval;
                    // do nothing
                }
                else
                {
                    // the source group has an approval
                    if (destinationApproval != null)
                    {
                        // destination group has an approval; check to see if we need to overwrite it
                        if (destinationApproval.Action != sourceApproval.Action)
                        {
                            if (destinationApproval.Action == UpdateApprovalAction.Uninstall)
                            {
                                // TODO : allow a rule to override this.
                                Console.WriteLine("Skipping copy of approval on {0} as marked for uninstall in {1}.", update.Title, destinationGroup.Name);
                            }
                            else
                            {
                                // the approvals are different; overwrite
                                Console.Out.WriteLine(
                                    "Changing approval for {0} from {1} to {2} for group {3}.",
                                    update.Title,
                                    destinationApproval.Action,
                                    sourceApproval.Action,
                                    destinationGroup.Name);
                                if (isTest)
                                {
                                    Console.Out.Write("(TEST) ");
                                }

                                Job.ApproveUpdateForTargetGroup(update, destinationGroup, isTest, null);
                            }
                        }
                    }
                    else
                    {
                        // destination group does not have an approval; approve
                        Console.Out.WriteLine(
                            "Approving {0} for {1} for group {2}.",
                            update.Title,
                            sourceApproval.Action,
                            destinationGroup.Name);
                        if (isTest)
                        {
                            Console.Out.Write("(TEST) ");
                        }

                        Job.ApproveUpdateForTargetGroup(update, destinationGroup, isTest, null);
                    }
                }
            }
        }