SDK: How to add an enhanced detection method into an application deployment type
Update #1: I have attached the sample as a .cs file to make it easier to consume
In my previous post I provided a simple sample on how to create an application with a very basic detection method. If you want to perform more advanced detection, you can leverage the desired configuration management (DCM) SDK to create an extremely rich set of conditions called enhanced detection methods (EHD).
These EHD classes require the DcmObjectModel.dll assembly which is located with the administrator console.
The sample here will demonstrate creating an EHD and adding it to a deployment type. Use the sample program in this post and replace the code between lines 34 and 35 with the code that follows:
Code Snippet
- installer.DetectionMethod = DetectionMethod.Enhanced;
- EnhancedDetectionMethod ehd = new EnhancedDetectionMethod();
- // Get value from this registry setting
- RegistrySetting registrySetting = new RegistrySetting(null);
- registrySetting.RootKey = RegistryRootKey.LocalMachine;
- registrySetting.Key = @"SOFTWARE\MyCompany\MyProduct";
- registrySetting.Is64Bit = true;
- registrySetting.ValueName = "IsInstalled";
- registrySetting.CreateMissingPath = false;
- registrySetting.SettingDataType = DataType.Int64;
- // Add the setting to the EHD
- ehd.Settings.Add(registrySetting);
- // The expected value of the detected registry key
- ConstantValue constValue = new ConstantValue("1", DataType.Int64);
- // Create the reference to the EHD setting
- SettingReference settingRef = new SettingReference(
- application.Scope,
- application.Name,
- application.Version.GetValueOrDefault(),
- registrySetting.LogicalName,
- registrySetting.SettingDataType,
- registrySetting.SourceType,
- false);
- settingRef.MethodType = ConfigurationItemSettingMethodType.Value;
- // Create a collection of operands, these will be compared in an Expression
- CustomCollection<ExpressionBase> operands = new CustomCollection<ExpressionBase>();
- operands.Add(settingRef);
- operands.Add(constValue);
- // Expression to verify that all of the operands meet the ExpressionOperator value
- Expression exp = new Expression(ExpressionOperator.IsEquals, operands);
- // Create the rule
- Rule rule = new Rule("MyRuleId", NoncomplianceSeverity.None, null, exp);
- // Now create the deployment type and bind it to the installer
- DeploymentType scriptDT = new DeploymentType(installer, ScriptInstaller.TechnologyId, NativeHostingTechnology.TechnologyId);
- scriptDT.Title = "My Application Installer";
- ehd.Rule = rule;
- // Now add the rule to the detection method.
- installer.EnhancedDetectionMethod = ehd;
This will show in the administrator console like this:
This is just one example of the kind of powerful detection you can perform with EHDs.
Similar code can be used for creating requirement rules as well (these are added into your DeploymentType.Rules collection).
Comments
Anonymous
May 03, 2012
Can you post how to configure the detection method to use the radio button "This registry key must exist on the target..."?Anonymous
May 13, 2013
Hi Adam,Could you provide an example of how create a rule to check to see if a registry key exists? Looks like it should be simpler than the example you provide here but I cannot see to figure out how to setup the Enhanced Detection Method Rule.Thanks!Anonymous
March 03, 2014
What CCM DLLs need to be referenced for this program to compile?Anonymous
November 17, 2014
Doesn't seem like it's documented but might also be helpful to others that for file/folder checks the additional properties can also be set.ConfigurationItemSettingMethodType.Value,"Version" for instanceA colleague of mine found these in the XML of SDMpackageDigest column in v_ConfigurationItemsAnonymous
January 26, 2015
Would be interesting to know how to add additional clause. I can add ehd.Settings.Add(anotherSetting);, but not clear what to do with another expression and rule?Anonymous
June 17, 2015
hi, thanks for this helpful post. What I need currently is, to add an additional rule. so I want to have 2 different rules, checking for regkey availability. (with an OR function "outside"). Beside this I also could not figure out, how to set the flag for "This registry setting must exist on the target system to indicate presence of this application". I would really appreciate your help on this. thanks!Anonymous
July 15, 2016
Do you have an example for adding multiple detection methods to a deployment type?Anonymous
October 24, 2016
Hello.I don't know if you can help me, but I have a question about the detection merhod.I'm using Powershell to automate the creation of applications on SCCM 2012 R2 SP1.I know how to create only one detection method (File/Folder, Registry, Product Code) using Powershell and it works perfectly.But I don't know how to add a second detection clause for the same application and same deployment type.Can you help me?Thank you in advance ! =)Ludovic