Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda