Hej has been asking me a series of questions regarding Dwords and related, Instead of just sending over the code (which was my initial intention)I have decided to create a "Article" / "Tut" as this can be usueful to developers for 100's of reasons.
Registry Keys Article/Tutorial
[IMG]http://i111.photobucke*****m/albums/n121/golmor/regeditsc.png[/IMG]
As always, Follow this article, read along, and open VB and start a new project and follow along.
Developers (Windows Developers) have been using the registry as a place to store application settings, and in some cases can be used to change settings of other applications, so the question becomes, how can we harnest this feature in VB.net
Definitions paraphrased by me (Original Source Wiki)
SubTree
- HKEY_CURRENT_USER
Configuration Settings of the user who logged on. (Currently) - HKEY_USERS
Contains all user profiles Settings. - HKEY_LOCAL_MACHINE
Contains Settings and configuration Information particular to the computer. - HKEY_CLASSES_ROOT
Contains data that associates extensions wiith the program, and configuration data for COM objects. - HKEY_CURRENT_CONFIG
Contains information about hardware used on system startup.
Subkeys and Values.
Paraphrased by me (original source WIKI)
- REG_SZ
A fixed-length text string. - REG_EXPAND_SZ
A variable-length text string. - REG_DWORD
A number that is 4 bytes (32 bits) long. (Data) - REG_MULTI_SZ
Multiple text strings formatted as an array of null strings
Microsoft.Win32 Namespace
- ClassesRoot
Read base key HKEY_CLASSES_ROOT. - CurrentConfig
Reads base key HKEY_CURRENT_CONFIG. - CurrentUser
Reads base key HKEY_CURRENT_USER - LocalMachine
Reads base key HKEY_LOCAL_MACHINE. - Users
Reads base key HKEY_USERS. - Name
Retrieves the name of key. - SubKeyCount
Retrieves the count of subkeys. - ValueCount
Retrieves the count of values. - Close
Closes the key. - CreateSubKey
Creates a subkey or opens one. - DeleteSubKey
Deletes a subkey. - DeleteSubKeyTree
Deletes a subkey and any child subkeys. - DeleteValue
Deletes the specified value from this key. - GetSubKeyNames
Retrieves an array of strings from all subkey names. - GetValue
Retrieves the specified value. - GetValueNames
Retrieves an array of strings from all names associated with the specified Key - OpenSubKey
Retrieves a specified subkey (with write access) - SetValue
Sets the specified value.
__________________________________________________ _______________
Example 1 (Create Subkey)
Code:
Dim rKey As RegistryKey
rKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
rKey.CreateSubKey("mpgh sample app")
rKey.Close()
What did this do?
This code created a subkey under HKLM\Software called "mpgh sample app".
Example 2 (Reading and Writing a Subkey)
Code:
Dim rKey As RegistryKey
Dim nr As Decimal
rKey = Registry.LocalMachine.OpenSubKey("Software\mpgh sample app", True)
rKey.SetValue("Application", "mpgh sample app")
nr = rKey.GetValue("Version", 0.0)
If nr < 1.2 Then
rKey.SetValue("Version", 1.3)
End If
rKey.Close()
and Finally the easiest of them all , Deleting a key
Code:
Dim rKey As RegistryKey
rKey = Registry.LocalMachine.OpenSubKey("Software", True)
rKey.DeleteSubKey("mpgh sample app", True)
rKey.Close()
In this example, The create "mpgh sample app" key is deleted
Hope this helps everyone who may need it, have fun and enjoy