Beispiel #1
0
 /// <summary>
 /// Apply settings to a Management object.
 /// </summary>
 /// <param name="target">The ManagamentObject to apply the settings to</param>
 /// <param name="properties">A Dictionary object containing the properties and their value.</param>
 /// <remarks>
 /// The properties Dictionary contains the name of the property as the key, and the value of the property as the value.
 /// </remarks>
 protected void ApplySettings(ManagementObject target, Dictionary<string, object> properties)
 {
     foreach (var kv in properties)
     {
         target.Properties[kv.Key].Value = kv.Value;
     }
     target.Put();
 }
Beispiel #2
0
        /// <summary>
        /// Copy a ManagementObject to a new Path
        /// </summary>
        /// <param name="MO"></param>
        /// <param name="Scope"></param>
        /// <param name="Dest"></param>
        static public void ManagementObjectCopy(ManagementBaseObject MO, ManagementScope Scope, ManagementPath Dest)
        {
            if (MO != null)
            {
                try
                {
                    ManagementObject MORemote = new ManagementObject();
                    ManagementClass RemoteClas = new ManagementClass(Scope, Dest, new ObjectGetOptions());
                    MORemote = RemoteClas.CreateInstance();

                    foreach (PropertyData PD in MO.Properties)
                    {
                        try
                        {
                            MORemote.Properties[PD.Name].Value = PD.Value;
                        }
                        catch { }
                    }
                    MORemote.Put();
                }
                catch { }
            }
        }
Beispiel #3
0
 void SetNTLMAuth(ManagementScope scope, string path)
 {
     var site = new ManagementObject(scope, new ManagementPath(path), null);
     site["AuthNTLM"] = true;
     site.Put();
 }
Beispiel #4
0
 void SetAuth(ManagementScope scope, string path, string authSetting, bool setting)
 {
     var site = new ManagementObject(scope, new ManagementPath(path), null);
     site[authSetting] = setting;
     site.Put();
 }
Beispiel #5
0
 private void SetAppPool(ManagementScope scope, string path, string appPoolId)
 {
     var site = new ManagementObject(scope, new ManagementPath(path), null);
     site["AppPoolId"] = appPoolId;
     site.Put();
 }
Beispiel #6
0
        private void AddScriptMapToSite(ManagementScope scope, string siteId, ScriptMap scriptMap)
        {
            var site = new ManagementObject(scope, new ManagementPath(String.Format(@"IIsWebVirtualDirSetting.Name=""W3SVC/{0}/root""", siteId)), null);
            var scriptMaps = (ManagementBaseObject[]) site["ScriptMaps"];

            var newScriptMaps = new ManagementBaseObject[scriptMaps.Length + 1];
            scriptMaps.CopyTo(newScriptMaps, 0);
            ManagementObject newScriptMap = new ManagementClass(scope, new ManagementPath("ScriptMap"), null).CreateInstance();
            newScriptMap["Extensions"] = scriptMap.Extension;
            newScriptMap["Flags"] = scriptMap.Flags;
            newScriptMap["IncludedVerbs"] = scriptMap.IncludedVerbs;
            newScriptMap["ScriptProcessor"] = scriptMap.Executable;
            newScriptMaps[newScriptMaps.Length - 1] = newScriptMap;

            site["ScriptMaps"] = newScriptMaps;
            site.Put();
        }
        /// <summary>
        /// Merges the XML data into local policy
        /// </summary>
        /// <param name="xDoc"></param>
        /// <param name="bPersistent"></param>
        /// <returns></returns>
        internal ManagementObject oImpSCCMPol(XmlDocument xDoc, bool bPersistent)
        {
            string sPolicyID = xDoc.DocumentElement.Attributes["PolicyID"].Value;

            ManagementObject MO = new ManagementObject();
            ManagementObject MORet = new ManagementObject();
            XmlNodeList xActions = xDoc.GetElementsByTagName("PolicyAction");
            foreach (XmlNode xNode in xActions)
            {
                if (string.Compare(xNode.Attributes["PolicyActionType"].Value, "WMI-XML", true) == 0)
                {
                    string sRuleId = xNode.ParentNode.Attributes["PolicyRuleID"].Value;
                    XmlNodeList xClasses = xNode.ChildNodes;

                    foreach (XmlNode xClass in xClasses)
                    {
                        /*ManagementObject MOPol = ImportSCCMPolicy(xClass, @"root\ccm\Policy", false);
                        MOPol.SetPropertyValue("PolicyID", sPolicyID);
                        MOPol.SetPropertyValue("PolicyRuleID", sRuleId);
                        MOPol.Put(); */

                        //Load Policy in RequestedConfig
                        ManagementObject MOReq = iImportSCCMPolicy(xClass, @"root\ccm\Policy\Machine\RequestedConfig", bPersistent);
                        MOReq.SetPropertyValue("PolicyID", sPolicyID);
                        MOReq.SetPropertyValue("PolicyRuleID", sRuleId);
                        MOReq.Put();

                        //Load Policy in ActualConfig
                        MO = iImportSCCMPolicy(xClass, @"root\ccm\Policy\Machine\ActualConfig", false);
                        MO.Put();

                        if (string.Compare(MO.SystemProperties["__Class"].Value.ToString(), "CCM_SoftwareDistribution", true) == 0)
                        {
                            MO.Get();
                            MORet = MO;
                        }
                    }
                }
            }
            return MORet;
        }