Пример #1
0
        private bool CreateDriverPackge()
        {
            string query = string.Format("SELECT * FROM SMS_DriverPackage WHERE NAME = '{0}'", Name);

            packageObject = Utility.GetFirstWMIInstance(connectionManager, query);

            if (packageObject == null)
            {
                IResultObject instance = connectionManager.CreateInstance("SMS_DriverPackage");
                instance["Name"].StringValue           = Name;
                instance["Description"].StringValue    = "";
                instance["PkgSourceFlag"].IntegerValue = 2;
                instance["PkgSourcePath"].StringValue  = Target;
                instance["PkgFlags"].IntegerValue     |= 16777216;
                // this is only supported on 1810 and above
                if (instance.PropertyList.ContainsKey("DriverManufacturer"))
                {
                    instance["DriverManufacturer"].StringValue = Vendor;
                }
                instance["Version"].StringValue = FileVersion;
                try
                {
                    instance.Put();
                    instance.Get();
                }
                catch (SmsQueryException ex)
                {
                    string str;
                    switch (ex.ExtendStatusErrorCode)
                    {
                    case 4:
                        str = "The driver package storage path is not empty.";
                        break;

                    case 1078462229:
                        str = "The system does not have read or write permissions to the driver package's source path.";
                        break;

                    default:
                        str = "An error occurred while importing the selected driver package.";
                        break;
                    }
                    Exception.Add(new SystemException(str));

                    return(false);
                }

                string folder = registry.ReadString("DriverPackageConsoleFolder");
                if (folder == "%MANUFACTURER%")
                {
                    folder = Vendor;
                }

                Utility.AddObjectToFolder(connectionManager, folder, instance["PackageID"].StringValue, 23);

                packageObject = instance;
            }

            return(true);
        }
Пример #2
0
        public static int?CreateFolder(ConnectionManagerBase connectionManager, string folderName, int objectType)
        {
            IResultObject instance = connectionManager.CreateInstance("SMS_ObjectContainerNode");

            instance["Name"].StringValue                   = folderName;
            instance["ObjectType"].IntegerValue            = objectType;
            instance["ParentContainerNodeID"].IntegerValue = 0;
            instance.Put();
            instance.Get();
            if (instance == null)
            {
                return(new int?());
            }
            return(new int?(instance["ContainerNodeID"].IntegerValue));
        }
Пример #3
0
        public bool CreateDeployment(IResultObject selectedObject)
        {
            IResultObject instance = connectionManager.CreateInstance("SMS_UpdateGroupAssignment");

            instance["AssignedUpdateGroup"].IntegerValue = selectedObject["CI_ID"].IntegerValue;

            instance["AssignedCIs"].IntegerArrayValue     = selectedObject["Updates"].IntegerArrayValue;
            instance["AssignmentName"].StringValue        = Name;
            instance["AssignmentDescription"].StringValue = "Generated by ConfigMgr Quick Tools";
            instance["ApplyToSubTargets"].BooleanValue    = false;
            instance["UseGMTTimes"].BooleanValue          = false;

            instance["TargetCollectionID"].StringValue = Collection["CollectionID"].StringValue;

            instance["NotifyUser"].BooleanValue       = NotifyUser;
            instance["UserUIExperience"].BooleanValue = UserUIExperience;

            instance["WoLEnabled"].BooleanValue = false;

            instance["StartTime"].DateTimeValue = StartTime;
            if (IsRequired)
            {
                instance["EnforcementDeadline"].DateTimeValue = DeadLineTime;
            }

            instance["SuppressReboot"].IntegerValue = SuppressReboot;
            instance["RebootOutsideOfServiceWindows"].BooleanValue = RebootOutsideOfServiceWindows;
            instance["OverrideServiceWindows"].BooleanValue        = OverrideServiceWindows;

            instance["Enabled"].BooleanValue = Enabled ? true : false;

            try
            {
                instance.Put();
                instance.Get();
            }
            catch (SmsQueryException ex)
            {
                Error = ex;
                return(false);
            }

            return(true);
        }
Пример #4
0
        private bool CreatePackge()
        {
            string query = string.Format("SELECT * FROM SMS_Package WHERE NAME = '{0}'", Name);

            packageObject = Utility.GetFirstWMIInstance(connectionManager, query);

            if (packageObject == null)
            {
                IResultObject instance = connectionManager.CreateInstance("SMS_Package");
                instance["Name"].StringValue           = Name;
                instance["Description"].StringValue    = "";
                instance["PkgSourceFlag"].IntegerValue = 2;
                instance["PkgSourcePath"].StringValue  = Target;
                instance["PkgFlags"].IntegerValue     |= 16777216;
                instance["Manufacturer"].StringValue   = Vendor;
                instance["Version"].StringValue        = FileVersion;
                try
                {
                    instance.Put();
                    instance.Get();
                }
                catch (SmsQueryException ex)
                {
                    Exception.Add(ex);

                    return(false);
                }

                Utility.AddObjectToFolder(connectionManager, registry.ReadString("LegacyConsoleFolder"), instance["PackageID"].StringValue, 2);

                packageObject = instance;
            }

            if (!Directory.Exists(Target))
            {
                Directory.CreateDirectory(Target);
            }

            return(true);
        }
Пример #5
0
 public static bool AddObjectToFolder(ConnectionManagerBase connectionManager, string folderName, string objectId, int objectType)
 {
     try
     {
         IResultObject resultObject1;
         try
         {
             string query = string.Format("SELECT * FROM SMS_ObjectContainerNode WHERE Name LIKE '{0}' AND ObjectType={1}", WqlEscapeString(folderName), objectType);
             resultObject1 = connectionManager.QueryProcessor.ExecuteQuery(query);
         }
         catch (SmsQueryException ex)
         {
             ExceptionUtilities.TraceException(ex);
             throw;
         }
         IResultObject resultObject2 = null;
         int?          nullable      = new int?();
         foreach (IResultObject resultObject3 in resultObject1)
         {
             if (resultObject3["ObjectType"].IntegerValue == objectType && resultObject3["ParentContainerNodeID"].IntegerValue == 0)
             {
                 resultObject2 = resultObject3;
                 break;
             }
         }
         if (resultObject2 == null)
         {
             try
             {
                 nullable = CreateFolder(connectionManager, folderName, objectType);
             }
             catch (Exception ex)
             {
                 ExceptionUtilities.TraceException(ex);
                 return(false);
             }
         }
         else
         {
             nullable = new int?(resultObject2["ContainerNodeID"].IntegerValue);
         }
         IResultObject resultObject4 = null;
         string        query2        = string.Format("Select * From SMS_ObjectContainerItem Where InstanceKey='{0}'", objectId);
         IResultObject resultObject5 = connectionManager.QueryProcessor.ExecuteQuery(query2);
         if (resultObject5 != null)
         {
             IEnumerator enumerator = resultObject5.GetEnumerator();
             if (enumerator.MoveNext())
             {
                 resultObject4 = (IResultObject)enumerator.Current;
             }
             if (resultObject4 != null)
             {
                 if (resultObject4["MemberID"] == null)
                 {
                     resultObject4 = null;
                 }
             }
         }
         if (resultObject4 == null)
         {
             resultObject4 = connectionManager.CreateInstance("SMS_ObjectContainerItem");
         }
         if (resultObject4 == null)
         {
             return(false);
         }
         resultObject4["InstanceKey"].StringValue      = objectId;
         resultObject4["ObjectType"].IntegerValue      = objectType;
         resultObject4["ContainerNodeID"].IntegerValue = nullable.Value;
         resultObject4.Put();
         resultObject4.Get();
         return(true);
     }
     catch (Exception ex)
     {
         ExceptionUtilities.TraceException(ex);
         return(false);
     }
 }
Пример #6
0
        internal bool CreateObjectFromInfFile(ConnectionManagerBase connectionManager)
        {
            Dictionary <string, object> methodParameters = new Dictionary <string, object>
            {
                { "DriverPath", Path.GetDirectoryName(InfLocation) },
                { "INFFile", Path.GetFileName(InfLocation) }
            };

            IResultObject driverObject = null;

            try
            {
                log.Debug("CreateFromINF: " + InfLocation);
                using (IResultObject resultObject = connectionManager.ExecuteMethod("SMS_Driver", "CreateFromINF", methodParameters))
                {
                    log.Debug("CreateInstance: " + InfLocation);
                    driverObject = connectionManager.CreateInstance(resultObject["Driver"].ObjectValue);
                }
            }
            catch (SmsQueryException ex)
            {
                // error 183 = driver exist, check if source content is ok.
                if (ex.ExtendStatusErrorCode == 183)
                {
                    if (ex.InnerException is ManagementException managementException)
                    {
                        try
                        {
                            // update content source path if it dose not exist
                            string query = string.Format("SELECT * FROM SMS_Driver WHERE CI_UniqueID='{0}'", managementException.ErrorInformation["ObjectInfo"].ToString());
                            driverObject = Utility.GetFirstWMIInstance(connectionManager, query);

                            if (!Directory.Exists(driverObject["ContentSourcePath"].StringValue))
                            {
                                log.Debug("UpdateContentSourcePath: " + driverObject["LocalizedDisplayName"].StringValue);
                                driverObject["ContentSourcePath"].StringValue = Path.GetDirectoryName(InfLocation);
                            }
                        }
                        catch (SmsQueryException ex1)
                        {
                            ManagementException mgmtException = ex.InnerException as ManagementException;
                            Exception = new SystemException(mgmtException.ErrorInformation["Description"].ToString());
                            log.Error(string.Format("ContentSourcePath: {0}, {1}, {2}", InfLocation, ex1.GetType().Name, Exception.Message));

                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (ex.ExtendStatusErrorCode == 13L)
                {
                    Exception = new SystemException("Invalid inf file.");
                    log.Error(string.Format("InvalidInf: {0}", InfLocation));

                    return(false);
                }
                else
                {
                    ManagementException mgmtException = ex.InnerException as ManagementException;
                    Exception = new SystemException(mgmtException.ErrorInformation["Description"].ToString());
                    log.Error(string.Format("Error: {0}", Exception.Message));

                    return(false);
                }
            }

            if (driverObject == null)
            {
                log.Debug("NoObject: " + InfLocation);

                return(false);
            }

            driverObject["IsEnabled"].BooleanValue = true;
            try
            {
                driverObject.Put();
                driverObject.Get();
            }
            catch (SmsQueryException ex)
            {
                ManagementException mgmtException = ex.InnerException as ManagementException;
                Exception = new SystemException(mgmtException.ErrorInformation["Description"].ToString());
                log.Error(string.Format("PutDriverObject: {0}, {1}, {2}", InfLocation, ex.GetType().Name, Exception.Message));

                return(false);
            }

            Object = driverObject;

            return(true);
        }