none
How to read and write registry key with form app RRS feed

  • Question

  • Hello everyone.ı want read  any registry key with form app and write any  .reg file with form app.How am ı do this



    • Edited by FromWorld Thursday, September 5, 2019 7:51 PM
    Thursday, September 5, 2019 7:48 PM

Answers

  • Hi FromWorld,

    To read or write registry key, you can try RegistryKey Class. And this simple demo may help you.

        private void Form1_Load(object sender, EventArgs e)
        {
            // Create a new SubKey for test
            RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey(@"Software\OurSettings");
        }
    
        // Write
        private void btWrite_Click(object sender, EventArgs e)
        {
            RegistryKey key= Registry.CurrentUser.OpenSubKey(@"Software\OurSettings",true);
            key.SetValue("keytest","valuetest");
        }
    
        // Read
        private void btRead_Click(object sender, EventArgs e)
        {
            RegistryKey regKeyAppRoot = Registry.CurrentUser.OpenSubKey(@"Software\OurSettings");
            String val = (string)regKeyAppRoot.GetValue("keytest");
            MessageBox.Show(val);
        }

    Also, you can refer to the following documents:

    How to: Create a Key In the Registry (Visual C#)

    RegistryKey.OpenSubKey Method

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 6, 2019 7:20 AM

All replies

  • Hi,

    You can find many articles by searching web.
    One example is Read and Write Windows Registry to Store Data Using C#.

    Regards

    Ashidacchi -- https://ssl01.rocketnet.jp/hokusosha.com/default.html

    Thursday, September 5, 2019 11:51 PM
  • Hello,

    • To create a registry file, create a text file, first line will be

      Windows Registry Editor Version 5.00

    • Write the contents.
    • Save it.

    How to create a file? See the docs.

    How to read/write to the registry? See the docs.

    Things that can go wrong with reading/writing to the registry, lack of proper permissions. That is simply a can of worms were the solution may be simple or having to go to a engineer to set permissions.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Thursday, September 5, 2019 11:53 PM
    Moderator
  • Hi FromWorld,

    To read or write registry key, you can try RegistryKey Class. And this simple demo may help you.

        private void Form1_Load(object sender, EventArgs e)
        {
            // Create a new SubKey for test
            RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey(@"Software\OurSettings");
        }
    
        // Write
        private void btWrite_Click(object sender, EventArgs e)
        {
            RegistryKey key= Registry.CurrentUser.OpenSubKey(@"Software\OurSettings",true);
            key.SetValue("keytest","valuetest");
        }
    
        // Read
        private void btRead_Click(object sender, EventArgs e)
        {
            RegistryKey regKeyAppRoot = Registry.CurrentUser.OpenSubKey(@"Software\OurSettings");
            String val = (string)regKeyAppRoot.GetValue("keytest");
            MessageBox.Show(val);
        }

    Also, you can refer to the following documents:

    How to: Create a Key In the Registry (Visual C#)

    RegistryKey.OpenSubKey Method

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 6, 2019 7:20 AM