T
T
TechNOIR2018-02-20 08:38:50
C++ / C#
TechNOIR, 2018-02-20 08:38:50

C#. How to get value from registry?

Good afternoon.
I'm trying to get a value from the registry in a Windows Forms project.
But I am getting errors. Tell me what did you do wrong?
And how to assign label1 as a result?

public MainForm()
    {
      //
      // The InitializeComponent() call is required for Windows Forms designer support.
      //
      InitializeComponent();
      RegistryKey readKey = Registry.CurrentUser.OpenSubKey("\\Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION");
      string loadString = (string)readKey.GetValue("devenv.exe");
      readKey.Close();
//
      // TODO: Add constructor code after the InitializeComponent() call.
      //
    }

Mistake:
System.NullReferenceException: Ссылка на объект не указывает на экземпляр объекта.

   в tttosto.MainForm..ctor() в c:\User\Documents\SharpDevelop Projects\tttosto\tttosto\MainForm.cs:строка 29
   в tttosto.Program.Main(String[] args) в c:\User\Documents\SharpDevelop Projects\tttosto\tttosto\Program.cs:строка 27

Line 29 in Mainform - string loadString = (string)readKey.GetValue("devenv.exe");
Line 27 in Program - Application.Run(new MainForm());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2018-02-20
@freeExec

There shouldn't be any slashes at the beginning . And then you can not immediately translate into the text. First you need to find out what type the key isOpenSubKey("Software\\
GetValueKind(name)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question