.

Saving and Loading data in the registry (new version)

fd

using System;
using Microsoft.Win32;

namespace Framework
{
    public static class RegistryAccess
    {
        //Loading a value:
        public static string LoadSettingFromRegistry(string _registryKey, string settingKey)
        {
            var MyKey = Registry.CurrentUser.OpenSubKey(_registryKey);
            if (MyKey == null)
                return null;
            var ValFromReg = (string) MyKey.GetValue(settingKey);
            MyKey.Close();
            return (ValFromReg != null) ? ValFromReg : null;
        }

        //Saving a value:
        public static void SaveSettingToRegistry<T>(string _registryKey, string settingKey, T value)
        {
            var MyKey = Registry.CurrentUser.CreateSubKey(_registryKey);
            var was = MyKey.GetValue(settingKey);
            MyKey.SetValue(settingKey, value);
            var isnow = MyKey.GetValue(settingKey);
            if (isnow.ToString() != value.ToString())
                throw new Exception("not changed");
            MyKey.Close();
        }
    }
}

d

 

Keys

for folder

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\Folder\shell\RunMyProcess\command]
@="RunProcess.exe"