Various operations on the registry under. Net

Source: Internet
Author: User


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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.