private IUpdate PublishUpdate(IUpdateCategory productToDelete, IUpdateCategory vendorToDelete) { Logger.EnteringMethod("Product to Delete : " + productToDelete.Title + " and Vendor to delete : " + vendorToDelete.Title); try { SoftwareDistributionPackage sdp = new SoftwareDistributionPackage(); string tmpFolderPath; sdp.PopulatePackageFromExe("ProductKiller.exe"); sdp.Title = "Delete Me !"; sdp.Description = "Delete Me !"; sdp.VendorName = vendorToDelete.Title; sdp.ProductNames.Clear(); sdp.ProductNames.Add(productToDelete.Title); sdp.PackageType = PackageType.Update; tmpFolderPath = GetTempFolder(); if (!System.IO.Directory.Exists(tmpFolderPath + sdp.PackageId)) { System.IO.Directory.CreateDirectory(tmpFolderPath + sdp.PackageId); } if (!System.IO.Directory.Exists(tmpFolderPath + sdp.PackageId + "\\Xml\\")) { System.IO.Directory.CreateDirectory(tmpFolderPath + sdp.PackageId + "\\Xml\\"); } if (!System.IO.Directory.Exists(tmpFolderPath + sdp.PackageId + "\\Bin\\")) { System.IO.Directory.CreateDirectory(tmpFolderPath + sdp.PackageId + "\\Bin\\"); } System.IO.FileInfo updateFile = new System.IO.FileInfo("ProductKiller.exe"); updateFile.CopyTo(tmpFolderPath + sdp.PackageId + "\\Bin\\" + updateFile.Name); sdp.Save(tmpFolderPath + sdp.PackageId + "\\Xml\\" + sdp.PackageId.ToString() + ".xml"); IPublisher publisher = wsus.GetPublisher(tmpFolderPath + sdp.PackageId + "\\Xml\\" + sdp.PackageId.ToString() + ".xml"); publisher.PublishPackage(tmpFolderPath + sdp.PackageId + "\\Bin\\", null); System.Threading.Thread.Sleep(5000); UpdateCollection publishedUpdates = productToDelete.GetUpdates(); if (publishedUpdates.Count == 1) { Logger.Write("Successfuly publish ProductKiller"); return(publishedUpdates[0]); } else { Logger.Write("Failed to publish ProductKiller"); return(null); } } catch (Exception ex) { Logger.Write("**** " + ex.Message); return(null); } }
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); }