private void SaveApplication(Microsoft.ConfigurationManagement.ApplicationManagement.Application applicationRequest) { //// Initialize application wrapper and factory for creating the SMS Provider application object. ApplicationFactory applicationFactory = new ApplicationFactory(); AppManWrapper applicationWrapper = AppManWrapper.Create(this.sccmConnection, applicationFactory) as AppManWrapper; //// Set the application into the provider object. applicationWrapper.InnerAppManObject = applicationRequest; applicationFactory.PrepareResultObject(applicationWrapper); applicationWrapper.InnerResultObject.Put(); }
private void btnAddRequirement_Click(object sender, EventArgs e) { this.SetNamedScopeForSCCMRequest(); ////retrieve the global condition to be associated by name WqlQueryResultsObject results = this.sccmConnection.QueryProcessor.ExecuteQuery(string.Format("SELECT * FROM SMS_GlobalCondition Where LocalizedDisplayName = '{0}'", cmbConditions.Items[cmbConditions.SelectedIndex])) as WqlQueryResultsObject; IResultObject result = null; foreach (IResultObject item in results) { result = item; break; } ////retrieve the application to add the global condition onto be name sccm.Application application = GetApplicationFromName(txtSCCMApplicationName.Text); if (result != null && application != null && application.DeploymentTypes.Any()) { ////need to get all the information for the result otherwise the call to the dcmobjectwrapper wont work result.Get(); ////Get the full id from the property of the result object string ciuniqueid = result.PropertyList["CI_UniqueID"]; ////It will contain the scope and ID which, both of which are needed seperately so split them on their seperator string[] ids = ciuniqueid.Split("/".ToCharArray()); string scope = ids[0]; string id = ids[1]; ////wrap up the wmi object in a wrapper object so it is possible to read out particular seetings DcmObjectWrapper dcmwrapper = DcmObjectWrapper.WrapExistingConfigurationItem(result) as DcmObjectWrapper; ComplexSetting complexsettings = dcmwrapper.InnerConfigurationItem.Settings; string name = complexsettings.ChildSimpleSettings[0].LogicalName; ////create the operands object which will set up ther comparison information CustomCollection <ExpressionBase> operands = new CustomCollection <ExpressionBase>(); ////Add the reference information to the global setting - note the assumption it is a string (this could also be read out of the object above) GlobalSettingReference setting = new GlobalSettingReference(scope, id, ScalarDataType.String, name, ConfigurationItemSettingSourceType.CIM); setting.SettingSourceType = ConfigurationItemSettingSourceType.Registry; setting.MethodType = ConfigurationItemSettingMethodType.Value; ////add the value into the value for the registry entry, note this example just focuses on string registry settings ConstantValue value = new ConstantValue(txtRequirementValue.Text, ScalarDataType.String); operands.Add(setting); operands.Add(value); ////for this example this requirement will check to see if something is of a particular value Expression exp = new Expression(ExpressionOperator.IsEquals, operands); ////Create a rule to add to the deplyment types requirement list Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.Rule rule = new Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.Rule("Rule_" + Guid.NewGuid().ToString("B").Replace("{", string.Empty).Replace("}", string.Empty), Microsoft.SystemsManagementServer.DesiredConfigurationManagement.Rules.NoncomplianceSeverity.None, null, exp); application.DeploymentTypes[0].Requirements.Add(rule); ////save the changes back to SCCM SaveApplication(application); } }
private void btnAddDependency_Click(object sender, EventArgs e) { ////retrieve the application that requires a dependency sccm.Application application = GetApplicationFromName(txtSCCMApplicationName.Text); ////retrieve the application that will form a dependency sccm.Application dependencyApplication = GetApplicationFromName(cmbDependency.Items[cmbDependency.SelectedIndex] as string); sccm.DeploymentType dependencydeploymentType = dependencyApplication.DeploymentTypes[0]; // define operands in an intent expression and add the information to the dependency CustomCollection <DeploymentTypeIntentExpression> operand = new CustomCollection <DeploymentTypeIntentExpression>(); operand.Add(new DeploymentTypeIntentExpression(dependencyApplication.Scope, dependencyApplication.Name, dependencyApplication.Version.Value, dependencydeploymentType.Scope, dependencydeploymentType.Name, dependencydeploymentType.Version.Value, DeploymentTypeDesiredState.Required, true)); ////create an expression (and/or) for multiple dependencies and then use in a rule which is added to the dependencies collection of the application's deployment type DeploymentTypeExpression expression = new DeploymentTypeExpression(ExpressionOperator.And, operand); DeploymentTypeRule dependencyRule = new DeploymentTypeRule("Dependency_" + Guid.NewGuid().ToString("B"), NoncomplianceSeverity.Critical, null, expression); application.DeploymentTypes[0].Dependencies.Add(dependencyRule); SaveApplication(application); }
private void btnSupersedeApplication_Click(object sender, EventArgs e) { ////retrieve app that was created sccm.Application application = GetApplicationFromName(txtSCCMApplicationName.Text); ////retrieve application that will be superseded sccm.Application appToSupersede = GetApplicationFromName(cmbSuperseded.Items[cmbSuperseded.SelectedIndex] as string); sccm.DeploymentType dt = application.DeploymentTypes[0]; sccm.DeploymentType ssdt = appToSupersede.DeploymentTypes[0]; //// Define an intent expression to describe the realtionship between the applications DeploymentTypeIntentExpression intentExpression = new DeploymentTypeIntentExpression(appToSupersede.Scope, appToSupersede.Name, (int)appToSupersede.Version, ssdt.Scope, ssdt.Name, (int)ssdt.Version, DeploymentTypeDesiredState.Prohibited, true); //// Define a deployment type rule to contain the expression DeploymentTypeRule deploymentRule = new DeploymentTypeRule(NoncomplianceSeverity.None, null, intentExpression); //// Add to Supersedes collection. dt.Supersedes.Add(deploymentRule); SaveApplication(application); }
private void btnCreateInstallerandDt_Click(object sender, EventArgs e) { ////Setup the installer and it's contents Content content = new Content(); MsiInstaller msiInstaller = new MsiInstaller(); FileInfo file = new FileInfo(txtMSILocation.Text); content.Location = file.Directory.FullName; ////use the msi folders location as the content source for the application package content = ContentImporter.CreateContentFromFolder(file.Directory.FullName); ////set the command that will run to install on a clients desktop msiInstaller.InstallCommandLine = txtInstallCommandLine.Text; msiInstaller.UninstallCommandLine = txtUninstallCommandLine.Text; ContentRef contentReferenece = new ContentRef(content); content.OnFastNetwork = ContentHandlingMode.Download; content.OnSlowNetwork = ContentHandlingMode.DoNothing; content.FallbackToUnprotectedDP = false; ////configure other properties - for instance the produce code which by default is used to detect whether the application is already installed msiInstaller.Contents.Add(content); msiInstaller.InstallContent = contentReferenece; msiInstaller.DetectionMethod = DetectionMethod.ProductCode; msiInstaller.ProductCode = txtProductCode.Text; msiInstaller.SourceUpdateProductCode = txtProductCode.Text; msiInstaller.ExecutionContext = sccm.ExecutionContext.System; msiInstaller.Contents[0].PinOnClient = false; msiInstaller.Contents[0].PeerCache = false; msiInstaller.UserInteractionMode = UserInteractionMode.Normal; msiInstaller.MaxExecuteTime = 120; msiInstaller.ExecuteTime = 0; ////Add a deployment type to the application using the installer details created above sccm.DeploymentType dt = new sccm.DeploymentType(msiInstaller, "MSI", NativeHostingTechnology.TechnologyId); dt.Title = txtSCCMApplicationName.Text; dt.Version = 1; ////retrieve tha application here to then add the deployment type to ot sccm.Application application = GetApplicationFromName(txtSCCMApplicationName.Text); application.DeploymentTypes.Add(dt); ////resave the application SaveApplication(application); }
private void button7_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(this.txtAppName.Text) && !string.IsNullOrEmpty(this.txtManufacturer.Text) && !string.IsNullOrEmpty(this.txtProductCode.Text) && !string.IsNullOrEmpty(this.txtSoftwareVersion.Text) && !string.IsNullOrEmpty(this.txtMSILocation.Text)) { if (!string.IsNullOrEmpty(this.txtSCCMApplicationName.Text)) { SetNamedScopeForSCCMRequest(); ////create a new application object and use the properties from the msi to set some of the properties sccm.Application applicationRequest = new sccm.Application(); applicationRequest.Publisher = this.txtManufacturer.Text; applicationRequest.SoftwareVersion = this.txtSoftwareVersion.Text; applicationRequest.Title = this.txtSCCMApplicationName.Text; applicationRequest.Version = 1; applicationRequest.DisplayInfo.DefaultLanguage = CultureInfo.CurrentCulture.Name; applicationRequest.AutoInstall = true; applicationRequest.Description = string.Format("Created using code for app {0}", this.txtSCCMApplicationName.Text); applicationRequest.ReleaseDate = DateTime.Now.ToString(); sccm.AppDisplayInfo displayInformation = new sccm.AppDisplayInfo(); displayInformation.Title = this.txtAppName.Text; displayInformation.Language = CultureInfo.CurrentCulture.Name; displayInformation.Publisher = this.txtManufacturer.Text; applicationRequest.DisplayInfo.Add(displayInformation); ////save the application in order to persist information SaveApplication(applicationRequest); } else { MessageBox.Show("Please specify an application name for SCCM."); } } else { MessageBox.Show("Please populate MSI properties"); } }