Resources » Code Snippets » Registry Operations

Registry Read and Write Using VB.Net


Posted Date: 05-Aug-2010  Last Updated:   Category: Registry Operations    
Author: Member Level: Silver    Points: 4


VB.Net Registry Operations



You can do basic Registry operations via Microsoft.Win32.Registry class.

1) Creating a Subkey


Imports Microsoft.Win32
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim regKey As RegistryKey
regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
regKey.CreateSubKey("MyApp")
regKey.Close()
End Sub
End Class


The code sample above creates a subkey called MyApp under HKLM\Software. Note that the second parameter True is used to indicate whether the key is writable. You can set it to False if you are just reading data from the registry.

2) Reading and writing values


Imports Microsoft.Win32
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim regKey As RegistryKey
Dim ver As Decimal
regKey = Registry.LocalMachine.OpenSubKey("Software\MyApp", True)
regKey.SetValue("AppName", "MyRegApp")
ver = regKey.GetValue("Version", 0.0)
If ver < 1.1 Then
regKey.SetValue("Version", 1.1)
End If
regKey.Close()
End Sub
End Class


Did you like this resource? Share it with your friends and show your love!

Responses to "Registry Read and Write Using VB.Net"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    Suresh
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India