Registry.OpenSubKey Returns Null
-
I'm trying to read in a list of VS2010 Projects from the registry:
private const string VS_PROJECT_MRU_PATH = @"Software\Microsoft\VisualStudio\10.0\ProjectMRUList";
public static List GetSubKeyNodeNames(BaseKey BaseKey, string SubKey)
{
List retVal = null;RegistryKey baseKey; if (SubKey != "") { baseKey = \_GetRegistryBaseKey(BaseKey); baseKey = baseKey.OpenSubKey(SubKey, false); //<===== FAILS HERE - basekey is null } else { baseKey = \_GetRegistryBaseKey(BaseKey); } if (baseKey == null && SubKey != "") { throw new Exception("Registry subkey not found"); } else { string\[\] names = baseKey.GetValueNames(); retVal = (from n in names select n).ToList(); } return retVal;
}
I have verified that the key DOES indeed exist. I just doesn't open. The problem is similar to this[^] except that I'm reading from HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE. Anyone know what;s going on here? Thanks
Everything makes sense in someone's mind
-
I'm trying to read in a list of VS2010 Projects from the registry:
private const string VS_PROJECT_MRU_PATH = @"Software\Microsoft\VisualStudio\10.0\ProjectMRUList";
public static List GetSubKeyNodeNames(BaseKey BaseKey, string SubKey)
{
List retVal = null;RegistryKey baseKey; if (SubKey != "") { baseKey = \_GetRegistryBaseKey(BaseKey); baseKey = baseKey.OpenSubKey(SubKey, false); //<===== FAILS HERE - basekey is null } else { baseKey = \_GetRegistryBaseKey(BaseKey); } if (baseKey == null && SubKey != "") { throw new Exception("Registry subkey not found"); } else { string\[\] names = baseKey.GetValueNames(); retVal = (from n in names select n).ToList(); } return retVal;
}
I have verified that the key DOES indeed exist. I just doesn't open. The problem is similar to this[^] except that I'm reading from HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE. Anyone know what;s going on here? Thanks
Everything makes sense in someone's mind
-
I'm trying to read in a list of VS2010 Projects from the registry:
private const string VS_PROJECT_MRU_PATH = @"Software\Microsoft\VisualStudio\10.0\ProjectMRUList";
public static List GetSubKeyNodeNames(BaseKey BaseKey, string SubKey)
{
List retVal = null;RegistryKey baseKey; if (SubKey != "") { baseKey = \_GetRegistryBaseKey(BaseKey); baseKey = baseKey.OpenSubKey(SubKey, false); //<===== FAILS HERE - basekey is null } else { baseKey = \_GetRegistryBaseKey(BaseKey); } if (baseKey == null && SubKey != "") { throw new Exception("Registry subkey not found"); } else { string\[\] names = baseKey.GetValueNames(); retVal = (from n in names select n).ToList(); } return retVal;
}
I have verified that the key DOES indeed exist. I just doesn't open. The problem is similar to this[^] except that I'm reading from HKEY_CURRENT_USER, not HKEY_LOCAL_MACHINE. Anyone know what;s going on here? Thanks
Everything makes sense in someone's mind
Where is the method
_GetRegistryBaseKey()
defined and what value is it supposed to return?Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
Where is the method
_GetRegistryBaseKey()
defined and what value is it supposed to return?Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
Here it is. This part works.
private static RegistryKey _GetRegistryBaseKey(BaseKey BaseKey)
{
RegistryKey key = null; ;switch (BaseKey) { case BaseKey.HKEY\_CLASSES\_ROOT: key = Registry.ClassesRoot; break; case BaseKey.HKEY\_CURRENT\_CONFIG: key = Registry.CurrentConfig; break; case BaseKey.HKEY\_CURRENT\_USER: key = Registry.CurrentUser; break; case BaseKey.HKEY\_DYN\_DATA: key = Registry.DynData; break; case BaseKey.HKEY\_LOCAL\_MACHINE: key = Registry.LocalMachine; break; case BaseKey.HKEY\_PERFORMANCE\_DATA: key = Registry.PerformanceData; break; } return key;
}
Everything makes sense in someone's mind
-
Here it is. This part works.
private static RegistryKey _GetRegistryBaseKey(BaseKey BaseKey)
{
RegistryKey key = null; ;switch (BaseKey) { case BaseKey.HKEY\_CLASSES\_ROOT: key = Registry.ClassesRoot; break; case BaseKey.HKEY\_CURRENT\_CONFIG: key = Registry.CurrentConfig; break; case BaseKey.HKEY\_CURRENT\_USER: key = Registry.CurrentUser; break; case BaseKey.HKEY\_DYN\_DATA: key = Registry.DynData; break; case BaseKey.HKEY\_LOCAL\_MACHINE: key = Registry.LocalMachine; break; case BaseKey.HKEY\_PERFORMANCE\_DATA: key = Registry.PerformanceData; break; } return key;
}
Everything makes sense in someone's mind
Works fine on my machine compiled as x86, x64 and Any CPU. Does your app run in restricted mode or is it a silverlight / web app or something? Does it run under a different user? Such as a service, web service, etc? Seems like a security / permission problem to me.
-
Here it is. This part works.
private static RegistryKey _GetRegistryBaseKey(BaseKey BaseKey)
{
RegistryKey key = null; ;switch (BaseKey) { case BaseKey.HKEY\_CLASSES\_ROOT: key = Registry.ClassesRoot; break; case BaseKey.HKEY\_CURRENT\_CONFIG: key = Registry.CurrentConfig; break; case BaseKey.HKEY\_CURRENT\_USER: key = Registry.CurrentUser; break; case BaseKey.HKEY\_DYN\_DATA: key = Registry.DynData; break; case BaseKey.HKEY\_LOCAL\_MACHINE: key = Registry.LocalMachine; break; case BaseKey.HKEY\_PERFORMANCE\_DATA: key = Registry.PerformanceData; break; } return key;
}
Everything makes sense in someone's mind
Based on your previous message, this cannot be true, since you stated that the key returned from this method is
null
. You need to use your debugger to see what value is being passed in to your code in the first place.Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
-
Based on your previous message, this cannot be true, since you stated that the key returned from this method is
null
. You need to use your debugger to see what value is being passed in to your code in the first place.Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness
I said OpenSubKey is returning False. _GetRegistryBaseKey return the correct base key. Then the call to OpenSubKey returns False.
Everything makes sense in someone's mind
-
Works fine on my machine compiled as x86, x64 and Any CPU. Does your app run in restricted mode or is it a silverlight / web app or something? Does it run under a different user? Such as a service, web service, etc? Seems like a security / permission problem to me.
SledgeHammer01 wrote:
Seems like a security / permission problem to me.
That's what I thought, but I'm running as an admin, with no restrictions that I know of. It's a WPF app.
Everything makes sense in someone's mind
-
SledgeHammer01 wrote:
Seems like a security / permission problem to me.
That's what I thought, but I'm running as an admin, with no restrictions that I know of. It's a WPF app.
Everything makes sense in someone's mind
Do you have a try / catch hiding exceptions at some level? That method throws an exception on errors. Looking at the .Net source, the only way you should get a null is if the Win32 native function is returning an error other then security. Unfortunately, .Net hides the real error code from you. You might want to call the native RegOpenKeyEx through interop so you can get the real error code.
-
I said OpenSubKey is returning False. _GetRegistryBaseKey return the correct base key. Then the call to OpenSubKey returns False.
Everything makes sense in someone's mind
Well my previous comment still stands; you need to use your debugger to check all values to determine why
OpenSubKey()
returnsnull
. With the information you have provided it's impossible to guess what values exist within your application.Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness