SetAccessRule() public method

public SetAccessRule ( RegistryAccessRule rule ) : void
rule RegistryAccessRule
return void
Esempio n. 1
0
        private static void Main(params string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine(Resources.Help);
                Pause();
                return;
            }

            if (args.Contains(Factory.FormFlag))
            {
                CommandLineBuilder form = new CommandLineBuilder();
                form.ShowDialog();
                return;
            }

            Console.WriteLine(Resources.NotifyStartMessage);

            Factory factory = new Factory();
            ExecutionInfo executionInfo = factory.CreateExecutationInfo();
            // TODO: validate parameters

            try
            {
                RegistryKey registryKey = branchRegistryKey[executionInfo.MainBranch];

                registryKey = registryKey.OpenSubKey(executionInfo.PathToKey, true);

                RegistryAccessRule registryAccessRule = new RegistryAccessRule(
                    executionInfo.User,
                    executionInfo.Permission,
                    executionInfo.InheritanceFlags,
                    executionInfo.PropagationFlags,
                    executionInfo.AccessControlType);

                RegistrySecurity registrySecurity = new RegistrySecurity();
                registrySecurity.SetAccessRule(registryAccessRule);
                registryKey.SetAccessControl(registrySecurity);

                Console.WriteLine(Resources.SuccessMessage);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: {0}", ex.ToString());
            }

            Pause();
        }