Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving the TextBox Values in Registry

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 ?

like image 466
user1410658 Avatar asked May 22 '12 16:05

user1410658


People also ask

What values can be stored in registry keys?

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

What are the three types of values in which stored in the registry?

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.

What is value data in regedit?

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.

What is a Reg_sz file?

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.


1 Answers

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.

like image 97
Bali C Avatar answered Oct 21 '22 09:10

Bali C