A DWORD is an unsigned integer and on x86 machines, a DWORD value is 32 bits long but simple string value is of 16 bits only. In my last article on Registry Editing using C#, I shared about creating simple string values in Registry Keys, but if you want to create DWORD you have to specify this while creating Values in Registry Key, otherwise it will consider your Value as string value.
- Use SetValue method present in RegistryKey class, to create new value field, with first parameter as value name, 2nd as its value, and third parameter of RegistryValueKind enumeration to specify the type of value.
RegistryKey rk = Registry.CurrentUser;
RegistryKey rk1 = rk.OpenSubKey("HowToIdeas”);
rk1.SetValue("newField", 4111, RegistryValueKind.DWord);
- The upper code will work perfectly and will create DWORD value in your Registry Key.
You can also download my sample project in which I have performed many functions like (Inserting, Editing, Searching, Deleting) on Registry Keys. Click Here To Download.