0

My C# application license manager is returning NULL when checking for a Key's existence even though the key exists and my application is installed. I have tried running as an Administrator and add or removing backslashes in the Key path.

        RegistryKey LitenUpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\LitenUp\NIT", false);
        if (LitenUpKey == null) {
            // Registry Key NOT Found
            return false;                
        }

proof it exists

NOTE: I am building as x64!

Sean Mitchell
  • 447
  • 2
  • 21
  • are your code is 32bit ? and which error returned ? – RbMm Dec 10 '17 at 00:15
  • @RbMm As stated it is reurning null when it should not be. – Sean Mitchell Dec 10 '17 at 00:16
  • I mean error code, which containing reason - why fail (dont know how this look in c#). and your code is 32 or 64 bit ? – RbMm Dec 10 '17 at 00:17
  • 1
    in case *x64* code - of course - key not exist - why you look under *wow6432node* ? you need use `KEY_WOW64_32KEY` access – RbMm Dec 10 '17 at 00:19
  • @RbMm Your sentence doesn't make sense, please rephrase it. :) – Sean Mitchell Dec 10 '17 at 00:22
  • @RbMm It was generated under wow6432node... – Sean Mitchell Dec 10 '17 at 00:23
  • if 64bit code want access 32-bit key it must use [`KEY_WOW64_32KEY`](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx) access. you in code use `SOFTWARE\LitenUp\NIT` and it 64bit - so why you in regedit look under `SOFTWARE\wow6432node\LitenUp\NIT`? – RbMm Dec 10 '17 at 00:26
  • @RbMm But, both applications are 64 bit and execute as such. – Sean Mitchell Dec 10 '17 at 00:29
  • *both applications* - in question visible only one application. if another application create key under *Wow6432Node* - it or 32bit or explicit use `KEY_WOW64_32KEY`. you need determinate for self - under which node you want create key and based on this - explicit use `KEY_WOW64_64KEY` (better) or `KEY_WOW64_32KEY` access – RbMm Dec 10 '17 at 00:33
  • @RbMm Can you link to a website where you learned about `KEY_WOW64_(64)or(32)KEY`. I want to learn more but your English no offense is making it very hard. Both the applications are x64 bit.I wrote to the key using `Registry.OpenSubKey("...").SetValue("item", "value")`. – Sean Mitchell Dec 10 '17 at 00:46
  • [Registry Reflection](https://msdn.microsoft.com/en-us/library/windows/desktop/aa384235(v=vs.85).aspx) – RbMm Dec 10 '17 at 00:48

1 Answers1

1

As @RbMm pointed out, the issues was in registry reflection between 32 bit and 64 bit. The following question showed me how to choose which view I saw. Here it is.

Sean Mitchell
  • 447
  • 2
  • 21