In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces how VB. NET access to the registry, has a certain reference value, interested friends can refer to, I hope you read this article after a great harvest, the following let Xiaobian with everyone to understand.
VB. NET is very easy to access the registry. We can use the registry class and registryKey class under the microsoft.Win32 namespace. Alternatively, My.Computer.Registry can return an instance of the Microsoft.Win32.Registry class.
Here are a few small examples of how VB. NET accesses the registry.
1. Returns or creates a registry key
Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser 'Return to current user key Dim Key2 As Microsoft.Win32.RegistryKey Key2 = Key1.OpenSubKey("northsnow") 'Returns the northsnow key under the current user key If Key2 Is Nothing Then Key2 = Key1.CreateSubKey("northsnow") 'Create key if it doesn't exist End If
2. Delete Registry Key
Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser 'Return to current user key Dim Key2 As Microsoft.Win32.RegistryKey Key2 = Key1.OpenSubKey("northsnow") 'Returns the northsnow key under the current user key If Not Key2 Is Nothing Then Key1.DeleteSubKey("northsnow") 'Create key if it doesn't exist End If
3. Create or read registry entries
Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser 'returns the current user key Dim Key2 As Microsoft.Win32.RegistryKey 2 = Key1.OpenSubKey("northsnow", True) ' returns the northsnow key under the current user key, If you want to create an item, you must specify the second parameter as true If Key2 Is Nothing Then Key2 = Key1.CreateSubKey ("northsnow") 'Create key if it does not exist End If ' Create item if it does not exist Overwrite Key2.SetValue if it exists ("name", "snow in the north") Key2.SetValue ("sex", True) Key2.SetValue ("age", 30) 'Return Item Value Dim sb As New System.Text.StringBuilder sb.AppendLine (Key2.GetValue("name")) sb.AppendLine (Key2.GetValue("sex")) sb.AppendLine (Key2.GetValue("age")) MsgBox (sb.ToString) 'Check if an item exists If (Key2.GetValue("name")) Is Nothing Then MsgBox("no") Else MsgBox("yes") End If If (Key2.GetValue("name2")) Is Nothing Then MsgBox("no") Else MsgBox("yes") End If
4. Traverse the registry
Dim sb As New System.Text.StringBuilder 'returns traversal results Dim sb2 As New System.Text.StringBuilder ' returns registry key read error Private Sub Button3_Click()Sub Button3_Click(ByVal sender As System.Object, Bye Val e As System.EventArgs) Handles Button3.Click Dim Key1 As Microsoft.Win32.RegistryKey Key1 = My.Computer.Registry.CurrentUser 'Returns to the current user key If Not Key1 Is Nothing Then sb.AppendLine (Key1.Name) readValue(Key1) readReg(Key1) End If Me.TextBox1.Text = sb.ToString Me.TextBox2.Text = sb2.ToString End Sub 'Traverse Registry Key Tree Private Sub readReg() Sub readReg (ByVal r As Microsoft.Win32.RegistryKey) If r.SubKeyCount > 0 Then Dim keyName() As String Dim keyTemp As Microsoft.Win32.RegistryKey keyName = r.GetSubKeyNames Dim i As Integer For i = 0 To keyName.GetLength(0) - 1 Try sb.AppendLine (keyName(i)) keyTemp = r.OpenSubKey (keyName(i), True) readValue(keyTemp) readReg(keyTemp) Catch ex As Exception sb2.AppendLine (keyName(i)) End Try Next End If End Sub 'Travels through items under a key Private Sub readValue()Sub readValue (ByVal r As Microsoft.Win32.RegistryKey) If r.ValueCount > 0 Then Dim valueName() As String Dim i As Integer valueName = r.GetValueNames For i = 0 To valueName.GetLength(0)-1 sb.AppendLine("###") sb.Append(r.Name) sb.Append("---") sb.Append(r.GetValue(valueName(i)).ToString) Next End If End Sub Thank you for reading this article carefully, I hope that Xiaobian shared "VB. NET how to access the registry" This article is helpful to everyone, but also hope that everyone supports, pay attention to industry information channels, more relevant knowledge waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.