Example #1
0
        protected override void ProcessRecord()
        {
            bool isChange = false;

            using (RegistryKey regKey = RegistryControl.GetRegistryKey(Path, false, true))
            {
                RegistrySecurity            security = regKey.GetAccessControl();
                AuthorizationRuleCollection rules    = security.GetAccessRules(true, false, typeof(NTAccount));
                if (All)
                {
                    //  テスト自動生成
                    TestGenerator.RegistryAccess(Path, "", false);

                    foreach (RegistryAccessRule rule in rules)
                    {
                        security.RemoveAccessRule(rule);
                        isChange = true;
                    }
                }
                else
                {
                    foreach (RegistryAccessRule rule in rules)
                    {
                        if (Account.Contains("\\") &&
                            rule.IdentityReference.Value.Equals(Account, StringComparison.OrdinalIgnoreCase))
                        {
                            //  テスト自動生成
                            TestGenerator.RegistryAccess(Path, RegistryControl.AccessRuleToString(rule), true);

                            security.RemoveAccessRule(rule);
                            isChange = true;
                        }
                        else if (!Account.Contains("\\") &&
                                 rule.IdentityReference.Value.EndsWith("\\" + Account, StringComparison.OrdinalIgnoreCase))
                        {
                            //  テスト自動生成
                            TestGenerator.RegistryAccess(Path, RegistryControl.AccessRuleToString(rule), true);

                            security.RemoveAccessRule(rule);
                            isChange = true;
                        }
                    }
                }
                if (isChange)
                {
                    regKey.SetAccessControl(security);
                }
            }
            WriteObject(new RegistryKeyInfo(Path, true));
        }
Example #2
0
        protected override void ProcessRecord()
        {
            bool isChange = false;

            using (RegistryKey regKey = RegistryControl.GetRegistryKey(Path, false, true))
            {
                if (regKey == null)
                {
                    return;
                }

                RegistrySecurity security = regKey.GetAccessControl();

                //  アクセス権設定
                if (!string.IsNullOrEmpty(Account))
                {
                    RegistryAccessRule rule = new RegistryAccessRule(
                        new NTAccount(Account),
                        (RegistryRights)Enum.Parse(typeof(RegistryRights), _Rights),
                        Recursive ?
                        InheritanceFlags.ContainerInherit :
                        InheritanceFlags.None,
                        PropagationFlags.None,
                        (AccessControlType)Enum.Parse(typeof(AccessControlType), AccessControl));

                    //  テスト自動生成
                    TestGenerator.RegistryAccess(Path, RegistryControl.AccessRuleToString(rule), true);

                    security.SetAccessRule(rule);
                    isChange = true;
                }

                //  Access文字列からの設定
                if (!string.IsNullOrEmpty(Access))
                {
                    /*
                     * foreach (RegistryAccessRule accessRule in RegistryControl.StringToAccess(Access))
                     * {
                     *  security.SetAccessRule(accessRule);
                     *  isChange = true;
                     * }
                     */
                    foreach (string ruleString in
                             Access.Contains("/") ? Access.Split('/') : new string[1] {
                        Access
                    })
                    {
                        //  テスト自動生成
                        TestGenerator.RegistryAccess(Path, ruleString, true);

                        security.SetAccessRule(RegistryControl.StringToAccessRule(ruleString));
                        isChange = true;
                    }
                }

                //  上位からのアクセス権継承の設定変更
                switch (Inherit)
                {
                case Item.ENABLE:
                    TestGenerator.RegistryInherit(Path, true);
                    security.SetAccessRuleProtection(false, false);
                    isChange = true;
                    break;

                case Item.DISABLE:
                    TestGenerator.RegistryInherit(Path, false);
                    security.SetAccessRuleProtection(true, true);
                    isChange = true;
                    break;

                case Item.REMOVE:
                    TestGenerator.RegistryInherit(Path, false);
                    security.SetAccessRuleProtection(true, false);
                    isChange = true;
                    break;
                }

                if (isChange)
                {
                    regKey.SetAccessControl(security);
                }
            }

            WriteObject(new RegistryKeyInfo(Path, true));
        }