示例#1
0
        public override bool Execute()
        {
            if (string.IsNullOrEmpty(Hive))
            {
                Hive = RegistryHive.LocalMachine.ToString();
            }
            var tempRegHive = Hive.Split(" ".ToCharArray()[0]);

            if (tempRegHive.Length != 1)
            {
                Log.LogError("WriteRegistry: Only 1 hive is allowed.");
                return(false);
            }
            RegistryHive regHive = (RegistryHive)System.Enum.Parse(typeof(RegistryHive), tempRegHive[0], true);

            // xbuild helpfully converts \ to / for us, even when we don't want it to
            var keyTmp          = Key.Replace('/', '\\');
            var pathParts       = keyTmp.Split("\\".ToCharArray(0, 1)[0]);
            var regKeyValueName = pathParts[pathParts.Length - 1];
            var regKey          = keyTmp.Substring(0, (keyTmp.Length - regKeyValueName.Length));

            if (String.IsNullOrEmpty(regKey))
            {
                Log.LogError("WriteRegistry: missing registry key.");
                return(false);
            }
            RegistryKey mykey = OpenRegKey(regKey, regHive);

            if (mykey == null)
            {
                Log.LogError("WriteRegistry: registry path not found - key='{0}'; hive='{1}';", regKey, regHive);
                return(false);
            }
            Log.LogMessage(MessageImportance.Low, "Setting {0} to {1}", regKeyValueName, Value);
            mykey.SetValue(regKeyValueName, Value);
            return(true);
        }