Exemplo n.º 1
0
        public static string GetValue(ManagementScope connectionScope,
                                      baseKey BaseKey,
                                      string key,
                                      string valueName,
                                      valueType ValueType)
        {
            string          typeOfValue  = RegistryMethod.ConvertGetValueType(ValueType);
            string          returnValue  = string.Empty;
            ManagementClass registryTask = new ManagementClass(connectionScope,
                                                               new ManagementPath("DEFAULT:StdRegProv"), new ObjectGetOptions());
            ManagementBaseObject methodParams = registryTask.GetMethodParameters(typeOfValue);

            methodParams["hDefKey"]     = BaseKey;
            methodParams["sSubKeyName"] = key;
            methodParams["sValueName"]  = valueName;

            ManagementBaseObject exitValue = registryTask.InvokeMethod(typeOfValue,
                                                                       methodParams, null);

            try{
                returnValue = exitValue["sValue"].ToString();
            }
            catch {
                try{ //ToDo: fix this ASAP, nested try/catch, I mean come on dude!
                    returnValue = exitValue["uValue"].ToString();
                }
                catch (SystemException e) {
                    returnValue = e.Message.ToString();
                }
            }
            return(returnValue);
        }
Exemplo n.º 2
0
 public override void DeleteKey(baseKey RootKey, string key)
 {
     if (IsConnected)
     {
         try
         {
             RegistryMethod.DeleteKey(connectionScope, RootKey, key);
         }
         catch (ManagementException err)
         {
             Console.WriteLine("An error occurred: " + err.Message);
         }
     }
 }
Exemplo n.º 3
0
 public override void CreateValue(baseKey RootKey, string key, string valueName, string value)
 {
     if (IsConnected)
     {
         try
         {
             RegistryMethod.CreateValue(connectionScope, RootKey, key, valueName, value);
         }
         catch (ManagementException err)
         {
             Console.WriteLine("An error occurred: " + err.Message);
         }
     }
 }
Exemplo n.º 4
0
        public override string GetValue(baseKey RootKey, string key, string valueName, valueType ValueType)
        {
            string Value = string.Empty;

            if (IsConnected)
            {
                try
                {
                    Value = RegistryMethod.GetValue(connectionScope, RootKey, key, valueName, ValueType);
                }
                catch (ManagementException err)
                {
                    Console.WriteLine("An error occurred: " + err.Message);
                }
            }
            return(Value);
        }
Exemplo n.º 5
0
        public override ArrayList EnumerateKeys(baseKey RootKey, string key)
        {
            ArrayList subKeys = new ArrayList();

            if (IsConnected)
            {
                try
                {
                    subKeys.AddRange(RegistryMethod.EnumerateKeys(connectionScope, RootKey, key));
                }
                catch (ManagementException err)
                {
                    Console.WriteLine("An error occurred: " + err.Message);
                }
            }
            return(subKeys);
        }
Exemplo n.º 6
0
        public static void SetValue(ManagementScope connectionScope,
                                    baseKey BaseKey,
                                    string key,
                                    string valueName,
                                    string value,
                                    valueType ValueType)
        {
            string          typeOfValue  = RegistryMethod.ConvertSetValueType(ValueType);
            string          returnValue  = string.Empty;
            ManagementClass registryTask = new ManagementClass(connectionScope,
                                                               new ManagementPath("DEFAULT:StdRegProv"), new ObjectGetOptions());
            ManagementBaseObject methodParams = registryTask.GetMethodParameters(typeOfValue);

            methodParams["hDefKey"]     = BaseKey;
            methodParams["sSubKeyName"] = key;
            methodParams["sValueName"]  = valueName;
            methodParams["sValue"]      = value;

            ManagementBaseObject exitValue = registryTask.InvokeMethod(typeOfValue,
                                                                       methodParams, null);
        }