Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 553
jeyejow Avatar asked Apr 04 '17 10:04

jeyejow


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


1 Answers

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!

like image 52
jeyejow Avatar answered Oct 24 '22 13:10

jeyejow