コード例 #1
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);
        }
コード例 #2
0
ファイル: RemoteHook.cs プロジェクト: tloeb/carteiro_win
        private IUpdate ImportPackage(IUpdateServer wsus, string packagepath, string title, string desc, string vendor)
        {
            //Be sure that the baseapplicabilityrules.xsd exists
            var schemaPathx86         = Path.Combine("C:\\Program Files (x86)", "Update Services\\Schema");
            var schemaPathx64         = Path.Combine("C:\\Program Files", "Update Services\\Schema");
            var updateservicesPathx86 = Path.Combine("C:\\Program Files (x86)", "Update Services");

            if (!File.Exists(schemaPathx86 + "baseapplicabilityrules.xsd"))
            {
                Console.WriteLine("INFO: Need to copy Update Services schemata into x86 Folder");
                Console.WriteLine("DEBUG: " + schemaPathx86);
                Console.WriteLine("DEBUG: " + schemaPathx64);
                Console.WriteLine("DEBUG: " + updateservicesPathx86);

                if (!Directory.Exists(updateservicesPathx86))
                {
                    Directory.CreateDirectory(updateservicesPathx86);
                    Console.WriteLine("INFO: Created Folder " + updateservicesPathx86);
                }
                if (!Directory.Exists(schemaPathx86))
                {
                    Directory.CreateDirectory(schemaPathx86);
                    Console.WriteLine("INFO: Created Folder " + schemaPathx86);

                    foreach (var file in Directory.GetFiles(schemaPathx64))
                    {
                        File.Copy(file, Path.Combine(schemaPathx86, Path.GetFileName(file)));
                        Console.WriteLine("INFO: Copy File " + file);
                    }
                }
            }

            Console.WriteLine("Installing Package...");
            SoftwareDistributionPackage sdp = new SoftwareDistributionPackage();

            sdp.PopulatePackageFromWindowsInstaller(packagepath);
            sdp.Title       = title;
            sdp.Description = desc;
            sdp.VendorName  = vendor;

            //Look for Windows Vista
            sdp.IsInstallable = "<bar:WindowsVersion Comparison='GreaterThanOrEqualTo' MajorVersion='6' MinorVersion='0' />";

            string sdpFilePath = Environment.GetEnvironmentVariable("TEMP") + "\\" + sdp.Title + sdp.PackageId.ToString() + ".txt";

            //Superseed Update if there is one existing
            var searchString = title.Split(' ')[0];

            foreach (IUpdate update in wsus.SearchUpdates(searchString))
            {
                sdp.SupersededPackages.Add(update.Id.UpdateId);
            }
            sdp.Save(sdpFilePath);
            IPublisher publisher = wsus.GetPublisher(sdpFilePath);
            FileInfo   dir       = new FileInfo(packagepath);

            publisher.PublishPackage(dir.Directory.ToString(), null);

            Console.WriteLine("CAB generated");
            IUpdate publishedUpdate = wsus.GetUpdate(new UpdateRevisionId(sdp.PackageId));

            return(publishedUpdate);
        }