Fail to read simple string from the registry ( code attached )
-
Try to read string from the registry - i get beck null all the time Code:
public static string ReadStringFromRegistry( string hive, string key )
{
string strRetVal = null;try { using( RegistryKey regKey = Registry.LocalMachine.OpenSubKey( hive ) ) { if( null != regKey ) { strRetVal = regKey.GetValue( key ) as string; if( String.IsNullOrEmpty( strRetVal ) ) { strRetVal = null; Debug.Assert( false, "fail to read from the registry" ); } } } } catch( Exception e ) { } return strRetVal; }
-
Try to read string from the registry - i get beck null all the time Code:
public static string ReadStringFromRegistry( string hive, string key )
{
string strRetVal = null;try { using( RegistryKey regKey = Registry.LocalMachine.OpenSubKey( hive ) ) { if( null != regKey ) { strRetVal = regKey.GetValue( key ) as string; if( String.IsNullOrEmpty( strRetVal ) ) { strRetVal = null; Debug.Assert( false, "fail to read from the registry" ); } } } } catch( Exception e ) { } return strRetVal; }
-
Your code is working fine for me, so there is nothing wrong with it. You probably have wrong input strings. Please check if "hive" and "key" are correct.
-
Thanks, In the line strRetVal = regKey.GetValue( key ) as string; i get strRetVal as null.
-
Thanks, In the line strRetVal = regKey.GetValue( key ) as string; i get strRetVal as null.
-
I read simple string that i created. If i try to read some other string ( that i did not created ) from the next hive - i see that the result are ok. Very Strange... P.S: using win7 - and i check the premmision of the registry access.
-
Try to read string from the registry - i get beck null all the time Code:
public static string ReadStringFromRegistry( string hive, string key )
{
string strRetVal = null;try { using( RegistryKey regKey = Registry.LocalMachine.OpenSubKey( hive ) ) { if( null != regKey ) { strRetVal = regKey.GetValue( key ) as string; if( String.IsNullOrEmpty( strRetVal ) ) { strRetVal = null; Debug.Assert( false, "fail to read from the registry" ); } } } } catch( Exception e ) { } return strRetVal; }
when you swallow exceptions like you do, you deserve the trouble you're getting. X|
Luc Pattyn [Forum Guidelines] [My Articles] [My CP bug tracking] Nil Volentibus Arduum
Season's Greetings to all CPians.