예제 #1
1
        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;
                }
            }
        }
예제 #2
1
 /// <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");
 }
예제 #3
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();
            }
        }
예제 #4
0
 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);
 }
예제 #5
0
 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;
     }
 }
예제 #6
0
        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;
            }
        }
예제 #7
0
 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;
     }
 }
예제 #8
0
        /// <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;
        }