public UInt32 UninstallMSI_ID(string MSIID) { ManagementObjectCollection CliAgents; WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\cimv2"; CliAgents = oProv.ExecuteQuery("SELECT * FROM Win32_Product WHERE IdentifyingNumber ='" + MSIID + "'"); foreach (ManagementObject CliAgent in CliAgents) { ManagementBaseObject inParams = CliAgent.GetMethodParameters("Uninstall"); ManagementBaseObject result = CliAgent.InvokeMethod("Uninstall", inParams, null); return UInt32.Parse(result.GetPropertyValue("ReturnValue").ToString()); } return 99; }
/// <summary> /// Delete all instances from a Query Result /// </summary> /// <param name="sNamespace"></param> /// <param name="sQuery"></param> public void DeleteQueryResults(string sNamespace, string sQuery) { try { WMI.Provider oProv = new WMI.Provider(this.mScope.Clone()); oProv.mScope.Path.NamespacePath = sNamespace; ManagementObjectCollection oResults = oProv.ExecuteQuery(sQuery); foreach (ManagementObject oInst in oResults) { oInst.Delete(); } } catch { } }
/// <summary> /// Get DCM Baselines (Class SMS_DesiredConfiguration) /// </summary> /// <returns>Class SMS_DesiredConfiguration</returns> public ManagementObjectCollection CCM_DCMBaselines() { if (oDCMBaselines == null) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\ccm\dcm"; ManagementObjectCollection MOC = oProv.ExecuteQuery("SELECT * FROM SMS_DesiredConfiguration"); oDCMBaselines = MOC; return MOC; } else { return oDCMBaselines; } }
/// <summary> /// The cached CCM_SoftwareDistributionClientConfig Class. /// </summary> /// <returns>root\ccm\policy\machine\requestedconfig:CCM_SoftwareDistributionClientConfig</returns> /// <seealso cref="M:smsclictr.automation.SMSComponents.CCM_SoftwareDistributionClientConfig(System.Boolean)"/> public ManagementObject CCM_SoftwareDistributionClientConfig() { if (oSMS_SoftwareDistributionClientConfig == null) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\ccm\policy\machine\requestedconfig"; ManagementObjectCollection MOC = oProv.ExecuteQuery("SELECT * FROM CCM_SoftwareDistributionClientConfig"); foreach (ManagementObject MO in MOC) { oSMS_SoftwareDistributionClientConfig = MO; return MO; } return null; } else { return oSMS_SoftwareDistributionClientConfig; } }
/// <summary> /// Get a all Advertisements (cached) from a specifed PackageID and ProgramName /// </summary> /// <param name="PKG_PackageId"></param> /// <param name="PRG_ProgramId"></param> /// <returns></returns> public List<ManagementObject> lGetAdverts(string PKG_PackageId, string PRG_ProgramId) { try { List<ManagementObject> oResult = new List<ManagementObject>(); //Check if ADV is Cached... oResult = ladvertisements.FindAll(p => (p.Properties["PKG_PackageID"].Value.ToString() == PKG_PackageId) & (p.Properties["PRG_ProgramID"].Value.ToString() == PRG_ProgramId)); if (oResult.Count > 0) { return oResult; } else { //Adv is not cached.. WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\ccm\Policy\Machine\ActualConfig"; ManagementObjectCollection MOC = oProv.ExecuteQuery("SELECT * FROM CCM_SoftwareDistribution WHERE PKG_PackageID = '" + PKG_PackageId + "' and PRG_ProgramID = '" + PRG_ProgramId + "'"); foreach (ManagementObject MOSW in MOC) { ladvertisements.Add(MOSW); oResult.Add(MOSW); } } return oResult; } catch { throw new System.Exception("Unable to get advertisements"); } }
/// <summary> /// Get a all Advertisements from a specifed PackageID and ProgramName /// </summary> /// <param name="PKG_PackageId"></param> /// <param name="PRG_ProgramId"></param> /// <returns></returns> public ManagementObjectCollection GetAdverts(string PKG_PackageId, string PRG_ProgramId) { try { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\ccm\Policy\Machine\ActualConfig"; return oProv.ExecuteQuery("SELECT * FROM CCM_SoftwareDistribution WHERE PKG_PackageID = '" + PKG_PackageId + "' and PRG_ProgramID = '" + PRG_ProgramId + "'"); } catch { throw new System.Exception("Unable to get advertisements"); } }
/// <summary> /// Get all ScheduleID's of a local Advertisement /// </summary> /// <param name="ADV_AdvertisementID">Advertisment ID</param> /// <param name="PKG_PackageID">Package ID</param> /// <param name="PRG_ProgramID">Program ID (Program Name)</param> /// <param name="UserSID">User Secirity Identifier (SID) or NULL for Machine</param> /// <returns></returns> public string[] GetSchedulIDs(string ADV_AdvertisementID, string PKG_PackageID, string PRG_ProgramID, string UserSID) { List<string> SchedID = new List<string>(); //Chekc if User or Machine is requested if (string.IsNullOrEmpty(UserSID)) UserSID = "Machine"; else UserSID = UserSID.Replace('-', '_'); try { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = string.Format(@"root\ccm\Policy\{0}\ActualConfig", UserSID); ManagementObjectCollection MOC = oProv.ExecuteQuery("SELECT * FROM CCM_Scheduler_ScheduledMessage WHERE ScheduledMessageID like '" + ADV_AdvertisementID + "-" + PKG_PackageID + "%'"); foreach (ManagementObject MO in MOC) { try { SchedID.Add(MO.Properties["ScheduledMessageID"].Value.ToString()); MO.Properties["Triggers"].Value = new string[] { "OneShot;MaxRandomDelay=0" }; MO.Put(); } catch { } } //W2k Support removed ... return SchedID.ToArray(); } catch { throw; } }
/// <summary> /// Get all Advertisements from a User /// </summary> /// <param name="SID">Security Identifier</param> /// <returns></returns> public ManagementObjectCollection GetAdvertisements(string SID) { EnumerationOptions oOptions = new EnumerationOptions(); //oOptions.ReturnImmediately = true; //oOptions.Rewindable = true; WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = string.Format(@"root\ccm\Policy\{0}\ActualConfig", SID); ManagementObjectCollection oResult = oProv.ExecuteQuery("SELECT * FROM CCM_SoftwareDistribution", oOptions); //Cache Adv... foreach (ManagementObject MO in oResult) { if (!lAdvertisements.Contains(MO)) { ladvertisements.Add(MO); } } return oResult; }
/// <summary> /// local CCM_ComponentClientConfig policy from requested policy /// </summary> /// <param name="ComponentName"></param> /// <returns>ROOT\ccm\Policy\Machine\RequestedConfig:CCM_ComponentClientConfig</returns> public ManagementObjectCollection Component_Requested(string ComponentName) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"ROOT\ccm\Policy\Machine\RequestedConfig"; return oProv.ExecuteQuery("SELECT * FROM CCM_ComponentClientConfig WHERE ComponentName = '" + ComponentName + "'"); }
/// <summary> /// CCM_ComponentClientConfig from actual policy /// </summary> /// <param name="ComponentName"></param> /// <returns>ROOT\ccm\Policy\Machine\ActualConfig:CCM_ComponentClientConfig</returns> public ManagementObject Component_Actual(string ComponentName) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"ROOT\ccm\Policy\Machine\ActualConfig"; ManagementObjectCollection MOC = oProv.ExecuteQuery("SELECT * FROM CCM_ComponentClientConfig WHERE ComponentName = '" + ComponentName + "'"); foreach (ManagementObject MO in MOC) { return MO; } return null; }