Sharing an example of how to work with the Registry in VB.NET.
In this example I am setting and retrieving the default folder to be used with the OpenFileDialog to set the initial folder.
defaultFolder is a Public variable.
Public Sub SaveSettingsToRegistry() Dim regKey As Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\YourAppName") regKey.SetValue("DefaultFolder", defaultFolder) regKey.Close() End Sub
Public Sub LoadSettingsFromRegistry() Dim regKey As Microsoft.Win32.RegistryKey Dim defaultVal As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\YourAppName") If regKey Is Nothing Then defaultFolder = defaultVal Else defaultFolder = regKey.GetValue("DefaultFolder", defaultVal) regKey.Close() End If End Sub
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visual Basic Forum.