Ejemplo n.º 1
0
        /// <summary>
        /// Add a script installer deployment type to an application, using registry key in HKLM
        /// </summary>
        public static void AddScriptInstaller(string applicationName, string installName, string hklmKey, bool is64bit, string valueName, string valueNameValue, string dataType, string expressionOperator, string installCommand, string uninstallCommand, int postInstallBehaviour, int userInteractMode, int maxExecTime, int estimateExecTime, int execContext, string server)
        {
            Application app = CMApplication.GetApplicationByName(applicationName, server);
            ScriptInstaller installer = ReturnStandardScriptInstaller(installCommand, uninstallCommand, postInstallBehaviour, userInteractMode, maxExecTime, estimateExecTime, execContext);

            installer.DetectionMethod = DetectionMethod.Enhanced;
            EnhancedDetectionMethod enhancedDetectionMethod = new EnhancedDetectionMethod();

            ConstantValue expectedValue = null;
            RegistrySetting registrySetting = new RegistrySetting(null);
            registrySetting.RootKey = RegistryRootKey.LocalMachine;
            registrySetting.Key = hklmKey;
            registrySetting.Is64Bit = is64bit;
            registrySetting.ValueName = valueName;
            registrySetting.CreateMissingPath = false;

            switch (dataType)
            {
                case "Version":
                    registrySetting.SettingDataType = DataType.Version;
                    expectedValue = new ConstantValue(valueNameValue, DataType.Version);
                    break;
                default:
                    break;
            }

            enhancedDetectionMethod.Settings.Add(registrySetting);

            SettingReference settingReference = new SettingReference(app.Scope, app.Name, app.Version.GetValueOrDefault(), registrySetting.LogicalName, registrySetting.SettingDataType, registrySetting.SourceType, false);
            settingReference.MethodType = ConfigurationItemSettingMethodType.Value;

            CustomCollection<ExpressionBase> operands = new CustomCollection<ExpressionBase>();
            operands.Add(settingReference);
            operands.Add(expectedValue);

            Expression expression = null;

            switch (expressionOperator)
            {
                case "IsEquals":
                    expression = new Expression(ExpressionOperator.IsEquals, operands);
                    break;
                case "LessEquals":
                    expression = new Expression(ExpressionOperator.LessEquals, operands);
                    break;
                default:
                    break;
            }

            Rule rule = new Rule(Guid.NewGuid().ToString("N"), NoncomplianceSeverity.None, null, expression);
            enhancedDetectionMethod.Rule = rule;

            installer.EnhancedDetectionMethod = enhancedDetectionMethod;

            DeploymentType deploymentType = new DeploymentType(installer, ScriptInstaller.TechnologyId, NativeHostingTechnology.TechnologyId);
            deploymentType.Title = installName;
            app.DeploymentTypes.Add(deploymentType);

            CMApplication.Save(app, server);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a script installer deployment type to an application, using registry key in HKLM
        /// </summary>
        public static void AddScriptInstaller(string applicationName, string installName, string hklmKey, bool is64bit, string valueName, string valueNameValue, string dataType, string expressionOperator, string installCommand, string uninstallCommand, int postInstallBehaviour, int userInteractMode, int maxExecTime, int estimateExecTime, int execContext, string server)
        {
            Application     app       = CMApplication.GetApplicationByName(applicationName, server);
            ScriptInstaller installer = ReturnStandardScriptInstaller(installCommand, uninstallCommand, postInstallBehaviour, userInteractMode, maxExecTime, estimateExecTime, execContext);

            installer.DetectionMethod = DetectionMethod.Enhanced;
            EnhancedDetectionMethod enhancedDetectionMethod = new EnhancedDetectionMethod();

            ConstantValue   expectedValue   = null;
            RegistrySetting registrySetting = new RegistrySetting(null);

            registrySetting.RootKey           = RegistryRootKey.LocalMachine;
            registrySetting.Key               = hklmKey;
            registrySetting.Is64Bit           = is64bit;
            registrySetting.ValueName         = valueName;
            registrySetting.CreateMissingPath = false;

            switch (dataType)
            {
            case "Version":
                registrySetting.SettingDataType = DataType.Version;
                expectedValue = new ConstantValue(valueNameValue, DataType.Version);
                break;

            default:
                break;
            }

            enhancedDetectionMethod.Settings.Add(registrySetting);

            SettingReference settingReference = new SettingReference(app.Scope, app.Name, app.Version.GetValueOrDefault(), registrySetting.LogicalName, registrySetting.SettingDataType, registrySetting.SourceType, false);

            settingReference.MethodType = ConfigurationItemSettingMethodType.Value;

            CustomCollection <ExpressionBase> operands = new CustomCollection <ExpressionBase>();

            operands.Add(settingReference);
            operands.Add(expectedValue);

            Expression expression = null;

            switch (expressionOperator)
            {
            case "IsEquals":
                expression = new Expression(ExpressionOperator.IsEquals, operands);
                break;

            case "LessEquals":
                expression = new Expression(ExpressionOperator.LessEquals, operands);
                break;

            default:
                break;
            }

            Rule rule = new Rule(Guid.NewGuid().ToString("N"), NoncomplianceSeverity.None, null, expression);

            enhancedDetectionMethod.Rule = rule;

            installer.EnhancedDetectionMethod = enhancedDetectionMethod;

            DeploymentType deploymentType = new DeploymentType(installer, ScriptInstaller.TechnologyId, NativeHostingTechnology.TechnologyId);

            deploymentType.Title = installName;
            app.DeploymentTypes.Add(deploymentType);

            CMApplication.Save(app, server);
        }