Vs.net provides a Microsoft.Win32 class with three subclasses, all for the registry, Microsoft.Win32.RegistryKey, Microsoft.Win32.Registry, Microsoft.Win32.RegistryHive
Microsoft.Win32.Registry provides access to the values of the root in each registry
Microsoft.Win32.Registry.CurrentUser ' as HKEY_CURRENT_USER root key
Microsoft.Win32.Registry.ClassesRoot ' as HKEY_CLASSES_ROOT root key
Microsoft.Win32.Registry.CurrentConfig ' as Hkey_current_config root key
Microsoft.Win32.Registry.Users ' as HKEY_USERS root key
Microsoft.Win32.Registry.DynDa ' corresponds to the Hkey_dyn_data primary key
Microsoft.Win32.Registry.PerformanceData ' corresponds to the Hkey_performance_data primary key
Microsoft.Win32.Registry.LocalMachine ' as HKEY_LOCAL_MACHINE root key
With so much to learn, let's do a registry operation. As a small example:
Dim Key as Microsoft.Win32.RegistryKey, subkey as Microsoft.Win32.RegistryKey
Key = Microsoft.Win32.Registry.CurrentUser ' key is HKEY_USERS root key
subkey = key. CreateSubKey ("software/vb.net") ' Creates a vb.net subkey under Hkey_users/software
subkey. SetValue ("Good?", "Of course") ' Set a key value under Hkey_users/software/vb.net, named Good?, value of course
The above is to create the key in the registry, below we use the program to access the registry we just created the key bar:
Key = Microsoft. Win32.Registry.CurrentUser ' above
Subkey=key. OpenSubKey ("Software/vb.net", True) ' subkey is the Hkey_users/software/vb.net key
Dim value as Object=subkey. GetValue ("Good?") ' Value is the good in the Hkey_users/software/vb.net key
MsgBox (Value.tostring ()) ' will appear in course
The above is to get the registry key value, to set the value, or with Subkey.setvalue
Let's say delete it:
Key. DeleteSubKey ("software/vb.net") ' Delete this key can also be used:
Key. Deletesubkeytree ("Software/vb.net")
You can also use key. Getsubkeynames to traverse the subkeys
That is, for i=0 to UBound (key. Getsubkeynames ())
Subkey=key. OpenSubKey (key. Getsubkeynames () (i), True)
....... ' Processing of each subkey
Next
With key. GetValueNames to traverse each value
That
For i=0 to UBound (key. GetValueNames ())
Key. GetValueNames () (i) ' is the name of each value
Value=key. Getvalue (key. GetValueNames () (i)) ' is the value of each value