简体   繁体   中英

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):

在此输入图像描述

Regardless, thanks!

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!

0000000c替换为12

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM