how to know whether a Registry key is exist?

how to know whether a Registry key is exist 
for example
RegistryKey rk = Registry.LocalMachine.OpenSubKey("Software\\myTestKey", 
true );

if myTestKey is not exist, I want to create it, and set some values to it.
if myTestKey is exist, I want to read values from it.

How to code with c# .net cf.

Thank you.


Answer this question

how to know whether a Registry key is exist?

  • DearME

    Check the return value of OpenSubKey() (as stored in rk) to see if it is null... if it is use CreateSubKey() to create the key as it does not already exist.

    Does this work for you



  • how to know whether a Registry key is exist?