Advertisement
TheVideoVolcano

Read/Write Registry VB.NET

Jun 16th, 2014
511
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.39 KB | None | 0 0
  1. 'Read/Write Boolean Values to and from Registry
  2.  
  3. Private prodVer As String = Application.ProductVersion.toString.remove(3,4)
  4.  
  5. 'useage
  6.  
  7. If Not readkey() then
  8. 'do stuff
  9. writekey(true)
  10. End If
  11.  
  12. 'subs & funcs
  13.  Private Sub writeKey(ByVal dontShowChangeLog As Boolean)
  14.  
  15.         Dim k As RegistryKey
  16.  
  17.         k = Registry.CurrentUser.OpenSubKey("Software\" & Application.ProductName & "\" & prodVer, True)
  18.  
  19.         If dontShowChangeLog = True Then
  20.  
  21.             k.SetValue("DontShowChangeLog", "True")
  22.  
  23.         Else
  24.             k.SetValue("DontShowChangeLog", "False")
  25.         End If
  26.  
  27.     End Sub
  28.  
  29.     Private Function readkey() As Boolean
  30.  
  31.         Dim k As RegistryKey
  32.  
  33.         k = Registry.CurrentUser.OpenSubKey("Software\" & Application.ProductName & "\" & prodVer, True)
  34.  
  35.         If k Is Nothing Then
  36.  
  37.             k = Registry.CurrentUser.OpenSubKey("Software", True)
  38.             k.CreateSubKey(Application.ProductName)
  39.             k = k.OpenSubKey(Application.ProductName, True)
  40.  
  41.             k.CreateSubKey(prodVer)
  42.             k = k.OpenSubKey(prodVer, True)
  43.  
  44.             k.SetValue("DontShowChangeLog", "False")
  45.  
  46.         End If
  47.  
  48.         If k.GetValue("DontShowChangeLog", "False") = "False" Then
  49.             Return False
  50.         ElseIf k.GetValue("DontShowChangeLog", "False") = "True" Then
  51.             Return True
  52.         End If
  53.  
  54.         Return Nothing
  55.     End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement