OpenSubKey() return a null value when existing the right key.

L

Leo

Hey, guys
Please see the code below:
/////************************************************
RegistryKey rkHive = null;
RegistryKey rk = null;
string target = "127.0.0.1";
rkHive = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine,
this.target);
try
{
rk = rkHive.OpenSubKey(oro.key.Value);
//rkHive = {HKEY_LOCAL_MACHINE}
//oro.key.Value="\\SOFTWARE\\Classes\\.wax"
//And its data type is string.
}
//after the operation
//rk = null;
//It is abnormal as there is the right key in the right position
catch (System.Exception e)
{
Log(e);
}
//////*****************************************************
We have some subkey below "HKEY_LOCAL_MACHINE\\SOFTWARE\\Classes\\.wax"
But after the operation the rk still equal to null and there isn't any
exception.

Has someone met the same situation?
 
G

Guest

Hi Leo,

When you open a SubKey, you must not have the preseding //. In your case
oro.key.Value should be SOFTWARE\\Classes\\.wax, not
\\SOFTWARE\\Classes\\.wax.

Cheers,
Chester
 
L

Leo

It is really make sence.
thanks, Chester.
It is so kind of you.

Cheers,
Leo

"Chester дµÀ£º
"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top