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:
- 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
- // 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(
- settingRef.MethodType = ConfigurationItemSettingMethodType.Value;
- // Create a collection of operands, these will be compared in an Expression
- CustomCollection<ExpressionBase> operands = new CustomCollection<ExpressionBase>();
- // 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).