Beruflich Dokumente
Kultur Dokumente
This is the next part of the previous tutorial. We'll learn here how to add, change, read, delete registry
keys and values using vb.net.
I included a sample that contains all those functionality.
Project details:
1- How to add a registry key/value
2- How to read a registry value
3- How to delete a key or a value
4- Changing a value or a key
5- Hints to use registry with VB.net
6- The registry reader (VB.net)
My.Computer.Registry.CurrentUser.CreateSubKey("TestKey")
This line will create a key in the HKEY_CURRENT_USER hive and will be named "testkey"
Now let's move on to see how to set a value.
For the value we'll need three things: Value path, Value name and value value. We can also precise
the value type if not Visual Basic will try to assign the value type depending on the object type.
Tip: Type "," and Visual Basic will show a list of value types.
The sample:
The sample contain two part, one for creating keys and the other to create values.
To create a key just put the named of the key and it'll be created in the Current_User folder.
To assign a value, type the complete path, for example "HKEY_CURRENT_USER\mykey" and then the
value name then the value content and click add to create it.
If you wish to do more complex things, like getting the keys in a hive and getting the values of keys...
Then you should see the registry viewer sample. (Download the source code to get it)
My.Computer.Registry.CurrentUser.DeleteSubKey("TestKey")
To delete a value
My.Computer.Registry.CurrentUser.ValueCount.ToString()
My.Computer.Registry.CurrentUser.SubKeyCount.ToString()
If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\MyKey", _
"TestValue", Nothing) Is Nothing Then
MsgBox("Value does not exist.")
Else
MsgBox("Value exist.")
End If
I have included an application with the source code. This one will resume all what we have done.
It's like the registry editor of Windows but still view only and can't edit values.