c# - Can't read value from existing key -


I can not read any value with a reg key. The path is correct for some strange reason .. and the key exists is. I do not know why it can not be read.

I have the code (which reads the registry)

  string local = Microsoft.Win32.Registry LocalMachine.ToString (); String javaarag path = "\\ software \\ javasoft \\ Java runtime environment \"; if (JavaRagpath! = Null) {string javaVersion = Registry.readReg (local + Java rigpath, "current version"). ToString (); string JavaHome = Registry.readReg (Javreg Path + "\\" + JavaWarsian, "Javomome"). ToString (); Return Javohom;} ​​  

Registry cs (read)

  public static object readReg (string keypath, string keyname) {key = Microsoft.Win32.Registry.CurrentUser OpenSubKey (mainpath); return key. Value (keyName);}   

And here is an image from Registry Editor. To verify the path and so on

But it only gives one NPE. ..

Message: An unbundled exception of type 'System.NullReferenceException' is in bookkeeping GUI Project.exe

Additional information: The object reference is not set for an instance of an object.

Any help on this?

some Problems that I see I am

The first readReg actually OpenSubKey > on the registry. Current user is calling . He reads from HKCU you need to use for Registry.LocalMachine to HKLM . Pass the root key as an additional parameter to readReg .

On top of that you may be redirected to your 32bit process (well, I believe your process is 32 bits) to the 32 bit view of the registry. But the key you are looking for is in the 64 bit view of the registry.

Your attempt to reach HKLM \ Software \ / code> in other words is being redirected to HKLM \ Software \ Wow6432Node .

Calculate your 32-bit process to allow access to the 64 bit views of the registry. Your readReg function should be modified to check the errors in the call on OpenSubKey . It can return the method null . You should deal with that scenario in a cleaner way, then throw a NullReferenceException .

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -