deleted
deleted

Reputation: 363

c# How write hex value in registry , instead of decimal value?

How can i write in registry DWORD hexadecimal value ? Instead of decimal value, like in this code example ?

RegistryKey key = Registry.LocalMachine;
key = klase.CreateSubKey(@"SYSTEM\CurrentControlSet\Control\Windows");
key.SetValue("CSDVersion2", "100", RegistryValueKind.DWord);
key.Close(); 

Solution is !

RegistryKey key = Registry.LocalMachine;
key = klase.CreateSubKey(@"SYSTEM\CurrentControlSet\Control\Windows");
key.SetValue("CSDVersion2", Convert.ToInt32("100", 16), RegistryValueKind.DWord);
key.Close(); 

Upvotes: 2

Views: 7238

Answers (2)

vcsjones
vcsjones

Reputation: 141668

SetValue takes an object, so you can give it a plain ol' integer. I would do something like this:

key.SetValue("CSDVersion2", 0x100, RegistryValueKind.DWord);

That sets CSDVersion2, to 0x100 hex, or 256 in decimal.

Upvotes: 3

Tigran
Tigran

Reputation: 62276

Using Convert.ToInt32(...) overload.

string strHexValue = Convert.ToInt32("100", 16).ToString();

where 16 is base.

Upvotes: 0

Related Questions