public string GetDWord(UInt32 hDefKey, string sSubKeyName, string sValueName, string DefaultValue) { { String result = ""; try { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"ROOT\default"; ManagementBaseObject inParams = oProv.GetClass("StdRegProv").GetMethodParameters("GetDWORDValue"); inParams["hDefKey"] = hDefKey; inParams["sSubKeyName"] = sSubKeyName; inParams["sValueName"] = sValueName; ManagementBaseObject outParams = oProv.ExecuteMethod("StdRegProv", "GetDWORDValue", inParams); if (outParams.GetPropertyValue("ReturnValue").ToString() == "0") { if (outParams.GetPropertyValue("uValue") != null) { result = outParams.GetPropertyValue("uValue").ToString(); } } return result; } catch { return DefaultValue; } } }
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> /// Install a Windows Installer Package /// </summary> /// <param name="sPath"></param> /// <param name="sOptions"></param> /// <returns>MSI Exit Code</returns> public UInt32 InstallMSI(string sPath, string sOptions) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\cimv2"; ManagementClass MC = oProv.GetClass("Win32_Product"); ManagementBaseObject inParams = MC.GetMethodParameters("Install"); inParams.SetPropertyValue("PackageLocation", sPath); inParams.SetPropertyValue("Options", sOptions); ManagementBaseObject Result = MC.InvokeMethod("Install", inParams, null); return (UInt32)Result.GetPropertyValue("ReturnValue"); }
/// <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; } }
public void SetDWord(UInt32 hDefKey, string sSubKeyName, string sValueName, UInt32 uValue) { try { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"ROOT\default"; ManagementBaseObject inParams = oProv.GetClass("StdRegProv").GetMethodParameters("SetDWORDValue"); inParams["hDefKey"] = hDefKey; inParams["sSubKeyName"] = sSubKeyName; inParams["sValueName"] = sValueName; inParams["uValue"] = uValue; ManagementBaseObject outParams = oProv.ExecuteMethod("StdRegProv", "SetDWORDValue", inParams); } catch { throw; } }
/// <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> /// 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; }
/// <summary> /// Default Constructor. Initiates the Provider object. /// </summary> /// <param name="oProvider">A Provider object.</param> public Schedules(WMI.Provider oProvider) { oWMIPrivider = new WMI.Provider(oProvider.mScope.Clone()); }
/// <summary> /// DesiredConfigurationManagement Constructor /// </summary> /// <param name="oProvider">A WMIProvider Instance</param> public DesiredConfigurationManagement(WMI.Provider oProvider) { oWMIProvider = new WMI.Provider(oProvider.mScope.Clone()); }
public void SetStringValue(UInt32 hDefKey, String sSubKeyName, String sValueName, String sValue) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"ROOT\default"; ManagementBaseObject inParams = oProv.GetClass("StdRegProv").GetMethodParameters("SetStringValue"); inParams["hDefKey"] = hDefKey; inParams["sSubKeyName"] = sSubKeyName; inParams["sValueName"] = sValueName; inParams["sValue"] = sValue; oProv.ExecuteMethod("StdRegProv", "SetStringValue", inParams); }
/// <summary> /// Default Constructor /// </summary> /// <param name="oProvider">WMI.Provider Instance</param> public SoftwareDistribution(WMI.Provider oProvider) { oWMIProvider = oProvider; }
/// <summary> /// Remove local persistent SoftwareDistribution policies /// </summary> /// <remarks>Wait or enforce a PolicyEvaluation cycle to enforce the process</remarks> public void CleanupPersistentPolicies() { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\CCM\Policy\Machine\RequestedConfig"; oProv.DeleteQueryResults("SELECT * FROM CCM_SoftwareDistribution WHERE PolicySource ='LOCAL'"); oProv.DeleteQueryResults("SELECT * FROM CCM_Scheduler_ScheduledMessage WHERE PolicySource ='LOCAL'"); }
/// <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> /// Import SCCM Policy from XML Node /// </summary> /// <param name="xClass"></param> /// <param name="sNamespacePath"></param> /// <param name="bPersistent"></param> /// <returns></returns> internal ManagementObject iImportSCCMPolicy(XmlNode xClass, string sNamespacePath, bool bPersistent) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = sNamespacePath; try { ManagementClass MC = oProv.GetClass(xClass.Attributes["class"].Value); ManagementObject MO = MC.CreateInstance(); foreach (XmlNode xProp in xClass.ChildNodes) { try { if (MO.Properties[xProp.Attributes["name"].Value].IsArray) { String[] aText = new String[xProp.ChildNodes.Count]; int i = 0; foreach (XmlNode xNode in xProp.ChildNodes) { aText[i] = xNode.InnerText; i++; } MO.SetPropertyValue(xProp.Attributes["name"].Value, aText); } else { string sValue = xProp.InnerText.Replace("\r\n\t", ""); sValue = sValue.Replace("\t\t", "").Trim(); MO.SetPropertyValue(xProp.Attributes["name"].Value, sValue); } } catch { } } if (string.Compare(MO.SystemProperties["__CLASS"].Value.ToString(), "CCM_SoftwareDistribution", true) == 0) { if (bPersistent) MO.SetPropertyValue("PolicySource", "LOCAL"); MO.SetPropertyValue("ADV_MandatoryAssignments", true); } //MO.Put(); return MO; } catch { } return null; }
/// <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> /// Constructor /// </summary> /// <param name="oProvider"></param> public Components(WMI.Provider oProvider) { oWMIProvider = oProvider; }
public void DeleteKey(UInt32 hDefKey, String sSubKeyName) { try { //Delete all subkeys ArrayList Subkeys = RegKeys(hDefKey, sSubKeyName); foreach (string skey in Subkeys) { DeleteKey(hDefKey, sSubKeyName + @"\" + skey); } WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"ROOT\default"; ManagementBaseObject inParams = oProv.GetClass("StdRegProv").GetMethodParameters("DeleteKey"); inParams["hDefKey"] = hDefKey; inParams["sSubKeyName"] = sSubKeyName; oProv.ExecuteMethod("StdRegProv", "DeleteKey", inParams); } catch { throw; } }
public List<string> RegValuesList(UInt32 hDefKey, string sSubKeyName) { try { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"ROOT\default"; ManagementBaseObject inParams = oProv.GetClass("StdRegProv").GetMethodParameters("EnumValues"); inParams["hDefKey"] = hDefKey; inParams["sSubKeyName"] = sSubKeyName; ManagementBaseObject outParams = oProv.ExecuteMethod("StdRegProv", "EnumValues", inParams); List<string> result = new List<string>(); if (outParams.GetPropertyValue("ReturnValue").ToString() == "0") { if (outParams.GetPropertyValue("sNames") != null) { result.AddRange(outParams.GetPropertyValue("sNames") as String[]); } } return result; } catch { throw; } }
/// <summary> /// Import a local Software Distribution Policy /// </summary> /// <param name="PolicyPath">Path to the XML File or URL on the SMS ManagementPoint</param> /// <param name="bPersistent">Create a persistant policy</param> /// <remarks>Persistant policies will not be removed automatically. Only a full/hard policy reset will remove these policies</remarks> /// <returns>CCM_SoftwareDistribution ManagementObject</returns> public ManagementObject ImportLocalPolicy(string PolicyPath, bool bPersistent) { string PolicyID = ""; string PolicyVersion = ""; ManagementObject SWDist = new ManagementObject(); try { XmlTextReader reader = new XmlTextReader(PolicyPath); reader.WhitespaceHandling = WhitespaceHandling.None; #region Extract MOF Data from XML while (!reader.EOF) { reader.Read(); if ((reader.Name == "Policy") & (reader.NodeType == XmlNodeType.Element)) { PolicyID = reader.GetAttribute("PolicyID"); PolicyVersion = reader.GetAttribute("PolicyVersion"); } if (reader.Name == "PolicyAction" & (reader.GetAttribute("PolicyActionType") == "WMI-MOF")) { reader.Read(); if ((reader.NodeType == XmlNodeType.CDATA) & (reader.HasValue)) { using (StreamWriter sw = new StreamWriter(Environment.ExpandEnvironmentVariables(@"%TEMP%\") + PolicyID + ".mof")) { sw.WriteLine(reader.Value); } } } } reader.Close(); #endregion #region Compile MOF to WMI //Compile the extracted MOF File to the local WMI Namespace root\ccm\policy ... Process mofcomp = new Process(); mofcomp.StartInfo.FileName = "mofcomp"; mofcomp.StartInfo.Arguments = @"-N:root\ccm\policy " + Environment.ExpandEnvironmentVariables(@"%TEMP%\") + PolicyID + ".mof"; mofcomp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; mofcomp.Start(); mofcomp.WaitForExit(); if (!mofcomp.HasExited) { mofcomp.Kill(); } mofcomp.Dispose(); #endregion #region Create remote policy //Copy the compiled local Policies... ManagementScope LocalScope = new ManagementScope(@"root\ccm\policy"); LocalScope.Connect(); WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\ccm\Policy"; SelectQuery Query = new SelectQuery("SELECT * FROM CCM_Scheduler_ScheduledMessage WHERE PolicyID='" + PolicyID + "'"); ManagementObjectSearcher searcher = new ManagementObjectSearcher(LocalScope, Query); ManagementObjectCollection SchedColl = searcher.Get(); foreach (ManagementObject MO in SchedColl) { WMI.Provider.ManagementObjectCopy(MO, oProv.mScope, new ManagementPath(@"\\" + oProv.mScope.Path.Server + @"\root\ccm\policy:CCM_Scheduler_ScheduledMessage")); } Query = new SelectQuery("SELECT * FROM CCM_SoftwareDistribution WHERE PolicyID='" + PolicyID + "'"); searcher = new ManagementObjectSearcher(LocalScope, Query); ManagementObjectCollection SWDistColl = searcher.Get(); foreach (ManagementObject MO in SWDistColl) { SWDist = MO; if (bPersistent) MO.SetPropertyValue("PolicySource", "LOCAL"); MO.SetPropertyValue("ADV_MandatoryAssignments", "True"); WMI.Provider.ManagementObjectCopy(MO, oProv.mScope, new ManagementPath(@"\\" + oProv.mScope.Path.Server + @"\root\ccm\policy:CCM_SoftwareDistribution")); } oProv.mScope.Path.NamespacePath = @"root\ccm\policy\machine\actualconfig"; foreach (ManagementObject MO in SchedColl) { //MO.SetPropertyValue("PolicySource", "LOCAL"); WMI.Provider.ManagementObjectCopy(MO, oProv.mScope, new ManagementPath(@"\\" + oProv.mScope.Path.Server + @"\root\ccm\policy\machine\actualconfig:CCM_Scheduler_ScheduledMessage")); } foreach (ManagementObject MO in SWDistColl) { //MO.SetPropertyValue("PolicySource", "LOCAL"); WMI.Provider.ManagementObjectCopy(MO, oProv.mScope, new ManagementPath(@"\\" + oProv.mScope.Path.Server + @"\root\ccm\policy\machine\actualconfig:CCM_SoftwareDistribution")); } if (bPersistent) { oProv.mScope.Path.NamespacePath = @"root\ccm\policy\machine\RequestedConfig"; foreach (ManagementObject MO in SchedColl) { MO.SetPropertyValue("PolicySource", "LOCAL"); WMI.Provider.ManagementObjectCopy(MO, oProv.mScope, new ManagementPath(@"\\" + oProv.mScope.Path.Server + @"\root\ccm\policy\machine\RequestedConfig:CCM_Scheduler_ScheduledMessage")); } foreach (ManagementObject MO in SWDistColl) { MO.SetPropertyValue("PolicySource", "LOCAL"); MO.SetPropertyValue("ADV_MandatoryAssignments", "True"); WMI.Provider.ManagementObjectCopy(MO, oProv.mScope, new ManagementPath(@"\\" + oProv.mScope.Path.Server + @"\root\ccm\policy\machine\RequestedConfig:CCM_SoftwareDistribution")); } } #endregion #region Delete local Policy foreach (ManagementObject MO in SWDistColl) { MO.Delete(); } foreach (ManagementObject MO in SchedColl) { MO.Delete(); } #endregion #region Delete remote Policy oProv.mScope.Path.NamespacePath = @"root\ccm\Policy"; oProv.DeleteQueryResults("SELECT * FROM CCM_Scheduler_ScheduledMessage WHERE PolicyID='" + PolicyID + "'"); oProv.DeleteQueryResults("SELECT * FROM CCM_SoftwareDistribution WHERE PolicyID='" + PolicyID + "'"); #endregion #region delete local .MOF File System.IO.File.Delete(Environment.ExpandEnvironmentVariables(@"%TEMP%\") + PolicyID + ".mof"); #endregion } catch { throw; } return SWDist; }
public Registry(WMI.Provider oProv) { oWMIProvider = oProv; }
public WindowsInstaller(WMI.Provider oProv) { oWMIProvider = oProv; }
public void TriggerScheduleID(string scheduleId, bool updateHistory) { WMI.Provider oProvider = new WMI.Provider(oWMIPrivider.mScope.Clone()); oProvider.mScope.Path.NamespacePath = @"ROOT\CCM"; mcSMSClass = oProvider.GetClass("SMS_Client"); inParams = mcSMSClass.GetMethodParameters("TriggerSchedule"); try { inParams["sScheduleID"] = scheduleId; oProvider.ExecuteMethod("SMS_Client", "TriggerSchedule", inParams); } catch { } if (updateHistory) { oProvider.mScope.Path.NamespacePath = @"ROOT\CCM\Scheduler"; ManagementObject mo = null; try { mo = oProvider.GetObject("CCM_Scheduler_History.ScheduleID='"+scheduleId+"',UserSID='Machine'"); } catch { } if (mo == null) { mo = oProvider.GetClass("CCM_Scheduler_History").CreateInstance(); mo.SetPropertyValue("ScheduleID", scheduleId); mo.SetPropertyValue("UserSID", "Machine"); mo.SetPropertyValue("FirstEvalTime", System.Management.ManagementDateTimeConverter.ToDmtfDateTime(DateTime.Now.ToUniversalTime())); } mo.SetPropertyValue("LastTriggerTime", System.Management.ManagementDateTimeConverter.ToDmtfDateTime(DateTime.Now.ToUniversalTime())); mo.Put(); } }
/// <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 a local Advertisement policy as ManagementObject /// </summary> /// <param name="ADV_AdvertisementId">Advertisement ID</param> /// <param name="PKG_PackageId">Package ID</param> /// <param name="PRG_ProgramId">Program ID (Program Name)</param> /// <returns>A ManagementObject with the local Advertisement Settings (root\ccm\Policy\Machine\ActualConfig:CCM_SoftwareDistribution)</returns> /// <remarks> /// <para>Policy Properties:</para> /// <code> /// ADV_ActiveTime /// ADV_ActiveTimeIsGMT /// ADV_ADF_Published /// ADV_AdvertisementID /// ADV_FirstRunBehavior /// ADV_MandatoryAssignments /// ADV_RCF_InstallFromLocalDPOptions /// ADV_RCF_InstallFromRemoteDPOptions /// ADV_RCF_PostponeToAC /// ADV_RepeatRunBehavior /// PKG_ContentSize /// PKG_Language /// PKG_Manufacturer /// PKG_MIFChecking /// PKG_MifFileName /// PKG_MIFName /// PKG_MIFPublisher /// PKG_MIFVersion /// PKG_Name /// PKG_PackageID /// PKG_PSF_ContainsSourceFiles /// PKG_SourceHash /// PKG_SourceVersion /// PKG_version /// PRG_CommandLine /// PRG_Comment /// PRG_DependentPolicy /// PRG_ForceDependencyRun /// PRG_HistoryLocation /// PRG_MaxDuration /// PRG_PRF_AfterRunning /// PRG_PRF_Disabled /// PRG_PRF_InstallsApplication /// PRG_PRF_MappedDriveRequired /// PRG_PRF_PersistMappedDrive /// PRG_PRF_RunWithAdminRights /// PRG_PRF_ShowWindow /// PRG_PRF_UserInputRequired /// PRG_PRF_UserLogonRequirement /// PRG_ProgramID /// PRG_ProgramName /// PRG_Requirements /// PRG_ReturnCodesSource /// PRG_WorkingDirectory /// </code> /// </remarks> public ManagementObject GetAdvert(string ADV_AdvertisementId, string PKG_PackageId, string PRG_ProgramId, string SID) { try { ManagementObject MO = ladvertisements.Find(p => (p.Properties["ADV_AdvertisementID"].Value.ToString() == ADV_AdvertisementId) & (p.Properties["PKG_PackageID"].Value.ToString() == PKG_PackageId) & (p.Properties["PRG_ProgramID"].Value.ToString() == PRG_ProgramId)); if (MO != null) { return MO; } SID = SID.Replace("-", "_"); WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); oProv.mScope.Path.NamespacePath = @"root\ccm\Policy\" + SID + @"\ActualConfig"; MO = oProv.GetObject("CCM_SoftwareDistribution.ADV_AdvertisementID='" + ADV_AdvertisementId + "',PKG_PackageID='" + PKG_PackageId + "',PRG_ProgramID='" + PRG_ProgramId + "'"); ladvertisements.Add(MO); return MO; } catch { throw new System.Exception("Unable to get advertisement"); } }
/// <summary> /// ReRun a scheduled Advertisement /// </summary> /// <param name="ADV_AdvertisementID">Advertisement ID</param> /// <param name="PKG_PackageID">Package ID</param> /// <param name="PRG_ProgramID">Program ID (Program Name)</param> /// <param name="UserSID">User Security Identifier (SID) or null for Machine</param> /// <returns>The restarted ScheduleID or NULL if the Advertisement does not have a valid ScheduleID</returns> /// <remarks>Only scheduled Advertisements (DateTime/As soon as possible/..) which are assigned to a Client can be restarted</remarks> public string RerunAdv(string ADV_AdvertisementID, string PKG_PackageID, string PRG_ProgramID, string UserSID) { WMI.Provider oProv = new WMI.Provider(oWMIProvider.mScope.Clone()); //Chekc if User or Machine is requested if (string.IsNullOrEmpty(UserSID)) UserSID = "Machine"; else UserSID = UserSID.Replace('-', '_'); oProv.mScope.Path.NamespacePath = string.Format(@"root\ccm\Policy\{0}\ActualConfig", UserSID); ManagementObject oAdv = oProv.GetObject(@"CCM_SoftwareDistribution.ADV_AdvertisementID='" + ADV_AdvertisementID + "',PKG_PackageID='" + PKG_PackageID + "',PRG_ProgramID='" + PRG_ProgramID + "'"); oAdv.SetPropertyValue("ADV_MandatoryAssignments", "True"); oAdv.SetPropertyValue("ADV_RepeatRunBehavior", "RerunAlways"); oAdv.Put(); ArrayList ScheduleIDs = new ArrayList(); ScheduleIDs.AddRange(GetSchedulIDs(ADV_AdvertisementID, PKG_PackageID, PRG_ProgramID, UserSID)); SMS.Schedules SMSSched = new SMS.Schedules(oProv); foreach (string sID in ScheduleIDs) { try { SMSSched.TriggerScheduleID(sID, false); return sID; } catch { } } return null; }