64-bit system, there is a difference in reading, there is no problem when writing. The code here is generic and already internally determines the number of bits in the current system.
1 /// <summary>2 ///Registration Form3 /// </summary>4 Public classRegistryKey645 {6 #regionStatic7 StaticIntPtr gethivehandle (registryhive hive)8 {9IntPtr Preexistinghandle =IntPtr.Zero;Ten OneIntPtr HKEY_CLASSES_ROOT =NewINTPTR (-2147483648); AINTPTR HKEY_CURRENT_USER =NewINTPTR (-2147483647); -INTPTR HKEY_LOCAL_MACHINE =NewINTPTR (-2147483646); -IntPtr HKEY_USERS =NewINTPTR (-2147483645); theIntPtr Hkey_performance_data =NewINTPTR (-2147483644); -IntPtr Hkey_current_config =NewINTPTR (-2147483643); -IntPtr Hkey_dyn_data =NewINTPTR (-2147483642); - Switch(Hive) + { - CaseRegistryHive.ClassesRoot:preexistingHandle = HKEY_CLASSES_ROOT; Break; + CaseRegistryHive.CurrentUser:preexistingHandle = HKEY_CURRENT_USER; Break; A CaseRegistryHive.LocalMachine:preexistingHandle = HKEY_LOCAL_MACHINE; Break; at CaseRegistryHive.Users:preexistingHandle = HKEY_USERS; Break; - CaseRegistryHive.PerformanceData:preexistingHandle = Hkey_performance_data; Break; - CaseRegistryHive.CurrentConfig:preexistingHandle = Hkey_current_config; Break; - CaseRegistryHive.DynData:preexistingHandle = Hkey_dyn_data; Break; - } - returnPreexistinghandle; in } - #endregion to + #regionStructure - PublicRegistryKey64 (registryhive hive, Registryview view) the { * This. View =view; $ This. Hive =Hive;Panax Notoginseng This. subkey =""; -Roothandle =NewSaferegistryhandle (Gethivehandle (Hive),true);//get the security handle of the root node the } + PublicRegistryKey64 (registryhive hive) A { the This. View = Environment.is64bitoperatingsystem?RegistryView.Registry64:RegistryView.Registry32; + This. Hive =Hive; - This. subkey =""; $Roothandle =NewSaferegistryhandle (Gethivehandle (Hive),true);//get the security handle of the root node $ } - #endregion - the #regionVariable -Saferegistryhandle Roothandle =NULL;//handle to the top-level nodeWuyiRegistryKey Subkeyhandle =NULL;//handle of the current subkey the - #endregion Wu - #regionProperty About /// <summary> $ ///Current Path - /// </summary> - Public stringsubkey {Get;Private Set; } - /// <summary> A ///top-level path + /// </summary> the PublicRegistryHive Hive {Get;Private Set; } - /// <summary> $ ///view mode the /// </summary> the PublicRegistryview View {Get;Private Set; } the /// <summary> the ///Internal system registry Information - /// </summary> in PublicRegistryKey RegistryKey {Get{return This. subkeyhandle?? Registrykey.fromhandle ( This. Roothandle, This. View); } } the #endregion the /// <summary> About ///for 32-bit program Access 64-bit registry the /// </summary> the /// <param name= "ValueName" >Item Name</param> the /// <returns>value</returns> + Public ObjectGetValue (stringvalueName) - { the return This. Subkeyhandle.getvalue (ValueName);//gets the value of the specified item under the keyBayi } the /// <summary> the ///Open Subkey - /// </summary> - /// <param name= "SubName" >subkey Name</param> the Public voidOpenkey (stringsubname) the { theRegistryKey key = This. Registrykey.opensubkey (subname); the if(key==NULL) -key= This. Registrykey.createsubkey (subname); the This. Subkeyhandle =key; the This. subkey + ="\\"+SubName; the }94 /// <summary> the ///64-bit registry for 32-bit program settings the /// </summary> the /// <param name= "ValueName" >Item Name</param>98 /// <param name= "value" >value</param> About /// <param name= "Kind" >value type</param> - Public voidSetValue (stringValueName,Objectvalue, RegistryValueKind kind)101 {102 This. Subkeyhandle.setvalue (ValueName, value, kind);103 }104}
How to use
1 New DTPM. Util.Configs.RegistryKey64 (registryhive.localmachine); 2 Key. Openkey (@ "software\xxx\xxx"); 3 string Path = key. GetValue ("configpath"asstring; 4 Key. Registrykey.close ();
If you have any improvement, please leave a message, thank you
C # 64-bit system registry read and write