I need some guidance in reading/writing/saving the values in Registry.I am new to this concept of saving things in registry
I have a Winform where i have to read/write to a App.config file and change the username and password using a winform.In my winform i have 2 textboxes and when i enter values and hit submit it changes the values in app.config.I somehow did that and no issues.
Now I need to send what ever values I have entered in the Textboxes to registry and save them thr and I should also be able to read them.
How shoud I do that ?
The possible types for a registry value are: string (REG_SZ or REG_MULTI_SZ), expandable string (REG_EXPAND_SZ), integer (REG_DWORD) and binary (REG_BINARY).
The values contain the actual information stored in the Registry. There are three types of values; String, Binary, and DWORD - the use of these depends upon the context.
A registry value can store data in various formats. When you store data under a registry value, for instance by calling the RegSetValueEx function, you can specify one of the following values to indicate the type of data being stored.
REG_SZ. A text string in a format which is convenient for human perception. Usually this data type is assigned to values that represent descriptions of components. This data type has a fixed length.
using Microsoft.Win32;
To write:
Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\MyProgram", "Username", "User1");
To read:
string username = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\MyProgram",
"Username", "NULL").ToString();
In read where I have put NULL
- thats the value to return if the value you are looking for isn't there.
So if you did:
if(username == "NULL")
{
// it doesn't exist, handle situation here
}
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With