/// <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;

        }
Beispiel #2
0
        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 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");
            }
        }