Possible to use Reflection on Registry Class? 
Author Message
 Possible to use Reflection on Registry Class?

Hi,

Is it possible to use reflection to get a RegistryKey from the Registry
class?
I tried the code below but since I can't declare the registry class As New
it wont work!
Perhaps I'm doing something wrong but don't know what.

x = GetRegKey("CurrentUser")  'For example

'Function to return the chosen registry key by its name.
Friend Function GetRegKey(ByVal strName As String) As RegistryKey
        Dim typRegType As Type
        Dim objRegistry As Registry
        Dim objFieldInfo As FieldInfo

        typRegType = objRegistry.GetType
        objFieldInfo = typRegType.GetField(strName)
        GetRegKey = objFieldInfo.GetValue(objFieldInfo)
End Function

--
Thanks in advance
Ali Eghtebas Sweden



Tue, 23 Aug 2005 18:26:18 GMT  
 Possible to use Reflection on Registry Class?

Quote:

> Is it possible to use reflection to get a RegistryKey from the Registry
> class? I tried the code below but since I can't declare the registry
> class As New it wont work!
> ...
>         typRegType = objRegistry.GetType

Try this:

   typRegType = Type.GetType("System.Win32.Registry")

- Brian



Wed, 24 Aug 2005 05:40:26 GMT  
 Possible to use Reflection on Registry Class?
Seems that the only one who understood my question is you Brian.
This doesn't work either. typRegType is still Nothing.
--
Regards
Ali Eghtebas Sweden
Quote:
> Try this:

>    typRegType = Type.GetType("System.Win32.Registry")

> - Brian



Thu, 25 Aug 2005 01:09:19 GMT  
 Possible to use Reflection on Registry Class?

Quote:

> This doesn't work either. typRegType is still Nothing.

Hmm.  Do either of these throw an exception?

    Type.GetType("System.Object", True, True)
    Type.GetType("Microsoft.Win32.Registry", True, True)

- Brian



Thu, 25 Aug 2005 05:49:45 GMT  
 Possible to use Reflection on Registry Class?
Thanks alot Brian!!! Type.GetType("Microsoft.Win32.Registry") worked like a
charm :)
I just didn't notice in your first post that you had "System.Win32.Registry"
instead of "Microsoft.Win32.Registry".
You made my day Brian :)
--
Regards
Ali Eghtebas Sweden


Quote:

> > This doesn't work either. typRegType is still Nothing.

> Hmm.  Do either of these throw an exception?

>     Type.GetType("System.Object", True, True)
>     Type.GetType("Microsoft.Win32.Registry", True, True)

> - Brian



Thu, 25 Aug 2005 06:20:40 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. It it possible to register an event using the System.Reflection

2. Using reflection to create class instance

3. Sub Class Reflection

4. VB2008: Getting the System.Reflection.PropertyInfo from within a class property

5. Setting a value in a structure using Reflection

6. Dynamic loading forms using reflection

7. Using Reflection to load Composite Control

8. Missing assembly when using reflection to call component method

9. Using a WRQ Reflection Session in a VB 6 Program

10. enumerate registry entries using win32api registry functions

11. enum registry subkeys using winAPI32 registry functions

12. Passing Classes to other classes (using user defined types)

 

 
Powered by phpBB® Forum Software