Example #1
0
        public override IEnumerable <CommandDTOBase?> Execute(string[] args)
        {
            var hive         = RegistryHive.LocalMachine;
            var keyPath      = "Software";
            var depth        = 0;
            var regex        = new Regex(".");
            var ignoreErrors = true;
            var computer     = "";

            if (args.Length == 0)
            {
                depth = 1;
                regex = new Regex("default");
            }
            if (args.Length >= 1)
            {
                var separatorPos = args[0].IndexOf("\\");
                if (separatorPos == -1)                   // e.g. HKLM
                {
                    hive    = RegistryUtil.GetHive(args[0]);
                    keyPath = "";
                }
                else if (separatorPos == args[0].Length)   // e.g. HKLM\
                {
                    var hiveStr = args[0].Substring(0, separatorPos);
                    hive    = RegistryUtil.GetHive(hiveStr);
                    keyPath = "";
                }
                else                                       // e.g. HKLM\Software
                {
                    var hiveStr = args[0].Substring(0, separatorPos);
                    hive    = RegistryUtil.GetHive(hiveStr);
                    keyPath = args[0].Substring(separatorPos + 1);
                }
            }
            if (args.Length >= 2)
            {
                if (!int.TryParse(args[1], out depth))
                {
                    WriteError("Could not parse depth argument");
                }
            }
            if (args.Length >= 3)
            {
                regex = new Regex(args[2], RegexOptions.IgnoreCase);
            }
            if (args.Length >= 4)
            {
                ignoreErrors = bool.Parse(args[3]);
            }
            if (args.Length >= 5)
            {
                computer = args[4];
            }


            foreach (var output in EnumerateRootKey(computer, hive, keyPath, regex, depth, ignoreErrors))
            {
                yield return(output);
            }
        }