public static SearchSession BeginSearch(this PSCmdlet cmdlet, bool force, string criterea)
        {
            IUpdateService2 service = cmdlet.GetService(force);


            UpdateSession    updateSession = new UpdateSession();
            IUpdateSearcher2 searcher      = updateSession.CreateSearcher();

            searcher.ServerSelection = ServerSelection.ssOthers;
            searcher.ServiceID       = service.ServiceID;


            SearchCompletedCallback callback = new SearchCompletedCallback(searcher);

            object state = new object();

            searcher.BeginSearch(criterea, callback, state);


            return(new SearchSession(callback));
        }
Example #2
0
        public static void GetWindowsUpdates()
        {
            Dictionary <string, string> wu;

            windowsUpdates = new List <Dictionary <string, string> >();

            UpdateSession updateSession = new UpdateSession();
            //IUpdateServiceManager2 USM = (IUpdateServiceManager2)new UpdateSession().CreateUpdateServiceManager();
            //IUpdateService US = USM.AddScanPackageService("Offline Sync Service", @"C:\Users\patilp\Downloads\wsusscn2.cab", 1);
            IUpdateSearcher2 uSearcher = (IUpdateSearcher2)updateSession.CreateUpdateSearcher();

            //uSearcher.Online = true;
            GetWindowsUpdatesHistory(uSearcher);

            Console.WriteLine("Update History");
            foreach (var Dict in UpdateIdsHistory)
            {
                foreach (var item in Dict)
                {
                    Console.WriteLine(item.Key + " : " + item.Value);
                }
                Console.WriteLine();
            }

            try
            {
                //uSearcher.ServerSelection = ServerSelection.ssDefault;
                Interop.WUApiLib.ISearchResult sResult = uSearcher.Search("IsHidden = 0 OR IsHidden = 1");

                Console.WriteLine();
                Console.WriteLine("---------------------------------------------------------");

                Console.WriteLine("Windows Update");
                foreach (Interop.WUApiLib.IUpdate5 update in sResult.Updates)
                {
                    try
                    {
                        wu                   = new Dictionary <string, string>();
                        wu["Title"]          = update.Title;
                        wu["UpdateID"]       = update.Identity.UpdateID.ToString();
                        wu["RevisionNumber"] = update.Identity.RevisionNumber.ToString();
                        //windowsUpdates.Add(wu);
                        if (!IfUpdateExist(update, UpdateIdsHistory))
                        {
                            foreach (var item in wu)
                            {
                                Console.WriteLine(item.Key + " : " + item.Value);
                            }

                            Console.WriteLine();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
 public SearchCompletedCallback(IUpdateSearcher2 updateSearcher)
 {
     UpdateSearcher = updateSearcher;
 }