static void Main(string[] args) { string Winrarpath = @"Software\MyTestKey"; string key = "MyKeyName"; string value = RegDll.GetRegistryValue(Winrarpath, key); RegDll.SetRegistryKey("HKEY_CURRENT_USER", Winrarpath, "MyKeyName", "hello"); Console.ReadLine(); }
public static void SetRegistryKey(string key, string subKey, string name, string value) { Console.WriteLine("SetRegistryKey start."); if (System.IntPtr.Size == 8) { // 写SOFTWARE\Huawei\VirtualDesktopAgent,需要关闭注册表重定向,再写64位路径的注册表 int ret = RegDll.Set64BitRegistryKey(key, subKey, name, value); if (ret != 0) { Console.WriteLine("Failed to write Reg {0}\\{1}\\{2},return {3}"); } } try { Microsoft.Win32.Registry.SetValue(key + "\\" + subKey, name, value); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("SetRegistryKey exit."); }