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(); } }