/// <summary> /// Gets the <see cref="Installation"/> class given the <see cref="Parameters"/>. /// </summary> /// <param name="param">The <see cref="Parameters"/> of the <see cref="Installation"/> to get.</param> /// <returns>An <see cref="Installation"/> given the <see cref="Parameters"/>.</returns> protected Installation GetInstallation(Parameters param) { Installation installation = null; try { if (string.IsNullOrEmpty(param.PatchCode)) { installation = ProductInstallation.GetProducts(param.ProductCode, param.UserSid, param.UserContext).FirstOrDefault(); } else { installation = PatchInstallation.GetPatches(param.PatchCode, param.ProductCode, param.UserSid, param.UserContext, PatchStates.All).FirstOrDefault(); } } catch (InstallerException ex) { var pse = new PSInstallerException(ex); if (null != pse.ErrorRecord) { base.WriteError(pse.ErrorRecord); } } return(installation); }
/// <summary> /// Enumerates patches for the given patch codes and ProductCodes and writes them to the pipeline. /// </summary> /// <param name="patchCode">The patch code to enumerate.</param> /// <param name="productCode">The ProductCode having patches to enumerate.</param> /// <param name="userSid">The user's SID for patches to enumerate.</param> /// <param name="context">The installation context for patches to enumerate.</param> /// <param name="filter">The patch installation state for patches to enumerate.</param> private void WritePatches(string patchCode, string productCode, string userSid, UserContexts context, PatchStates filter) { foreach (PatchInstallation patch in PatchInstallation.GetPatches(patchCode, productCode, userSid, context, filter)) { this.WritePatch(patch); } }
public static bool IsPatchAlreadyInstalled(string productCode, string patchCode) { var patches = PatchInstallation.GetPatches(null, productCode, null, UserContexts.Machine, PatchStates.Applied); return(patches.Any(patch => patch.DisplayName == patchCode)); }
public string[] GetNodes(InventoryDataLoadStatusCallback statusCallback) { ArrayList nodes = new ArrayList(); statusCallback(nodes.Count, @"Products\...\Patches"); foreach (ProductInstallation product in ProductInstallation.AllProducts) { string productName = MsiUtils.GetProductName(product.ProductCode); bool addedRoot = false; foreach (PatchInstallation productPatch in PatchInstallation.GetPatches(null, product.ProductCode, null, UserContexts.All, PatchStates.Applied)) { if (!addedRoot) { nodes.Add(String.Format(@"Products\{0}\Patches", productName)); } nodes.Add(String.Format(@"Products\{0}\Patches\{1}", productName, productPatch.PatchCode)); } } statusCallback(nodes.Count, "Patches"); string[] allPatches = GetAllPatchesList(); if (allPatches.Length > 0) { nodes.Add("Patches"); foreach (string patchCode in allPatches) { nodes.Add(String.Format(@"Patches\{0}", patchCode)); nodes.Add(String.Format(@"Patches\{0}\Patched Products", patchCode)); } statusCallback(nodes.Count, String.Empty); } return((string[])nodes.ToArray(typeof(string))); }
/// <summary> /// Returns true if given patch is uninstalled from all the target products /// </summary> /// <param name="patchCode"></param> /// <param name="targetProdCodes"></param> /// <returns></returns> public static bool IsPatchUninstalled(string patchCode, string[] targetProdCodes) { bool found = true; foreach (string targetProdCode in targetProdCodes) { // Exclude the patch verification for those products which are not installed if (!MsiUtils.IsProductInstalled(targetProdCode)) { continue; } foreach (PatchInstallation patch in PatchInstallation.GetPatches(patchCode, targetProdCode, null, UserContexts.All, PatchStates.All)) { if (patch.PatchCode == patchCode) { found = false; } } // Return after first occurance of found. That is it will return false if patch is applied to any of the target products. if (!found) { return(found); } } return(found); }
private DataView GetProductPatchData(string productCode) { DataTable table = new DataTable("ProductPatches"); table.Locale = CultureInfo.InvariantCulture; table.Columns.Add("ProductPatchesPatchCode", typeof(string)); foreach (PatchInstallation patch in PatchInstallation.GetPatches(null, productCode, null, UserContexts.All, PatchStates.Applied)) { table.Rows.Add(new object[] { patch.PatchCode }); } return(new DataView(table, "", "ProductPatchesPatchCode ASC", DataViewRowState.CurrentRows)); }
private DataView GetPatchTargetData(string patchCode) { DataTable table = new DataTable("PatchTargets"); table.Locale = CultureInfo.InvariantCulture; table.Columns.Add("PatchTargetsProductName", typeof(string)); table.Columns.Add("PatchTargetsProductCode", typeof(string)); foreach (PatchInstallation patch in PatchInstallation.GetPatches(patchCode, null, null, UserContexts.All, PatchStates.Applied)) { if (patch.PatchCode == patchCode) { string productName = MsiUtils.GetProductName(patch.ProductCode); table.Rows.Add(new object[] { productName, patch.ProductCode }); } } return(new DataView(table, "", "PatchTargetsProductName ASC", DataViewRowState.CurrentRows)); }
private static void AddRow(ProductInstallation p) { myRow r = new myRow(p); rows.Add(r); Logger.LogMsg(r.ToString()); try { IEnumerable <PatchInstallation> patches = PatchInstallation.GetPatches(null, p.ProductCode, null, UserContexts.All, PatchStates.All); foreach (PatchInstallation patch in patches) { myRow patchRow = new myRow(patch); rows.Add(patchRow); Logger.LogMsg(patchRow.ToString()); } }catch (Exception ex) { Logger.LogError("AddRow:" + ex.Message); } }
public static void GetAllProducts() { var allPrds = ProductInstallation.GetProducts(null, null, UserContexts.All); int i = 0; if (isFilterOn && filterString != "") { root.Text = System.Environment.MachineName + " filtered by \"" + filterString + "\""; } else { root.Text = System.Environment.MachineName; } foreach (ProductInstallation p in allPrds) { // if (string.IsNullOrEmpty(p.ProductName)) continue; if (isFilterOn && filterString != "") { if (string.IsNullOrEmpty(p.ProductName)) { continue; } else if (!p.ProductName.ToLower().Contains(filterString.ToLower())) { continue; } } try { UpdateProgress("Processing (" + i + ") " + p.ProductName); i++; //if (i > 40) break; TreeNode node = new TreeNode(p.ProductName); node.Name = p.ProductName; root.Nodes.Add(node); TreeNode nodeProp = new TreeNode("Properties"); node.Nodes.Add(nodeProp); try { AddProductProperty(nodeProp, p); } catch (Exception ex) { TreeNode error = new TreeNode(ex.Message); nodeProp.Nodes.Add(error); Logger.LogError(p.ProductName + ":" + ex.Message); } List <PatchInstallation> patches = PatchInstallation.GetPatches(null, p.ProductCode, null, UserContexts.All, PatchStates.All).ToList(); if (patches.Count > 0) { TreeNode pa = new TreeNode("Patches"); node.Nodes.Add(pa); foreach (PatchInstallation pch in patches) { TreeNode nd = new TreeNode(pch.DisplayName); nd.Name = pch.DisplayName; pa.Nodes.Add(nd); try { AddPatchProperty(nd, pch); } catch (Exception ex) { TreeNode error = new TreeNode(ex.Message); nd.Nodes.Add(error); Logger.LogError(pch.DisplayName + ":" + ex.Message); } } } if (p.Features != null) { List <FeatureInstallation> lst = p.Features.ToList(); if (lst.Count > 0) { TreeNode pa = new TreeNode("Features"); node.Nodes.Add(pa); foreach (FeatureInstallation fi in lst) { string txt = "FeatureName : " + fi.FeatureName + "; State : " + fi.State.ToString(); TreeNode nd = new TreeNode(txt); nd.Name = nd.Text; pa.Nodes.Add(nd); nd.ImageIndex = 1; nd.SelectedImageIndex = 1; } } } } catch (Exception ex) { Logger.LogError("GetAllProducts:ProductCode:" + p.ProductCode + "\n" + ex.Message); } } }