Example #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);
        }