Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
RegistryKey.OpenBaseKey or Registry.LocalMachine.OpenSubKey always return null in my VS2019 application

I am trying to validate the registry keys my WinForms app with VS2019(.Net 4.7.2). I have tried all the solutions out there(but nothing worked) for the same issue such as,

(a). Setting the Application build to AnyCPU/x64/x86

(b). Unchecking the Prefe 32-bit checkbox.

(c). Running my VS as an Admin.

(d). Checked the permissions of the key and its accessible to Everyone with Full Control enabled.

string var1 = Environment.UserDomainName + "\\" + Environment.UserName;
using(RegistryKey localMachine = Environment.Is64BitProcess ? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64) : Registry.LocalMachine) {

  var key = localMachine.OpenSubKey("Computer\\HKEY_LOCAL_MACHINE");
}

using(RegistryKey registry = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64).OpenSubKey("Computer\\HKEY_LOCAL_MACHINE")) {

}
using(RegistryKey key = Registry.LocalMachine.OpenSubKey("Computer\\HKEY_LOCAL_MACHINE")) {
  if (key != null) {
    
  }
}

       

Tried all the variations to read the directory, but not working.

Is it because of the Domain and Username? Environment.UserDomainName gives my company Domain and Environment.UserName gives the username I logged into my computer.

Can some one help me what or where I need to change to get the keys?

enter image description here

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!