Get/Set User Registry : Registry « Development Class « C# / C Sharp






Get/Set User Registry

        

using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Win32;

public static class Utils
{
    public static IDictionary<string, object> GetUserRegistry(string key)
    {
        Dictionary<string, object> result = null;
        RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(key);
        if (registryKey != null)
        {
            result = new Dictionary<string, object>();
            foreach (string name in registryKey.GetValueNames())
            {
                result.Add(name, registryKey.GetValue(name));
            }
            registryKey.Close();
        }
        return result;
    }
    public static void SetUserRegistry(string key, IDictionary<string, object> pairs)
    {
        RegistryKey registryKey = Registry.CurrentUser.CreateSubKey(key);
        if (registryKey == null)
        {
            throw new Exception("cannot create registry key: " + key);
        }
        foreach (string name in pairs.Keys)
        {
            registryKey.SetValue(name, pairs[name]);
        }
        registryKey.Close();
    }
}

   
    
    
    
    
    
    
    
  








Related examples in the same category

1.Registry.LocalMachine
2.Write a Text and DWord Value to the Registry
3.Enumerating Registry Keys
4.Retrieve the CPU Type and Speed from the Registry
5.Use GetValue and SetValue to get and save value to Registry
6.Get the Registry key found for CurrentUser
7. Accessing the Registry
8.Open a SubKey in Registry
9.Get Registry value Get Registry value
10.Registry File Association
11.Check Registry to see if it is installed
12.Copy Registry
13.Registry Utils
14.Retrieves any Registry value that uses the REGBINARY data type.
15.Writes a Registry value to the Registry.
16.Get IIS version