jeyejow
jeyejow

Reputation: 429

C# Registry Subkey dword value

Im making a program that sees if a subkey in Registry exist and, if it doesnt exist it will create a subkey with a value (dword). This program is being create to replace a .bat file that people (non programmers) had to run to execute the .reg file in order to the things i listed above, witch isnt verry appealing for the user, thats why im making this program.

The .reg file sets the keys i want to set as dword, but the value has a 'c' in the end (this is what it looks like):

[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU]
"ScheduledInstallTime"=dword:0000000c

and my c# code looks like this:

RegistryKey rk = Registry.LocalMachine.CreateSubKey(Globais.subkeyWU + @"\AU");
rk.SetValue("ScheduledInstallTime", 0000000c, RegistryValueKind.DWord);

The problem is that the .SetValue function doesnt accept the c in the end of the value, my guess is that it can only be numbers since its a dwrod (not sure), so, annyone knows how do i, bsaicly, do the same thing the .reg file is doing? maybe is hex values, something i dont know how to make in C#...

annyway, here is a printscreen on how it looks in the regedit (the .reg file does this):

enter image description here

Regardless, thanks!

Upvotes: 7

Views: 14832

Answers (2)

user7813631
user7813631

Reputation: 11

Replace 0000000c by 12

rk.SetValue("ScheduledInstallTime", 12, RegistryValueKind.DWord);

Upvotes: 1

jeyejow
jeyejow

Reputation: 429

After reading the comments in my post, I can awnser my own question!

The solution to my problem is:

rk.SetValue("ScheduledInstallTime", 0x0000000c, RegistryValueKind.DWord);

or

rk.SetValue("ScheduledInstallTime", 12, RegistryValueKind.DWord);

Because im trying to store a hexadecimal value in the registry, i either translate it do decimal or type the full hexadecimal value, like i did above.

Thanks for the comments, really made me understand and solve my problem!

Upvotes: 9

Related Questions