In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how VB.NET traverses registry keys. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The VB.NET traversal registry code is as follows:
Imports Microsoft.Win32 Public Class Form1 Dim KeyUsers As RegistryKey''display user list' summary >''display the user's list object param >' 'remarks > Private Sub ListAllUsers (ByVal list As ListBox)' clear the contents in the list list.Items.Clear () 'traverse the subkey For Each keyname As String In KeyUsers.GetSubKeyNames () list.Items.Add (keyname) Next End Sub' under the user key. Determine whether the user exists''summary >' username param >''. Return true Otherwise, return falsereturns > 'remarks > Private Function IsUserExists (ByVal username As String) As Boolean' to traverse the subkey For Each keyname As String In KeyUsers.GetSubKeyNames () under the user key'if the user exists, return true If (keyname.ToUpper () = username.ToUpper () Then Return True End If Next Return False End Function 'delete the user' summary > 'deleted username param >' 'remarks > Private Sub DeleteUser (ByVal username As String) ) If (IsUserExists (username)) Then 'delete the user's corresponding key KeyUsers.DeleteSubKey (username) ListAllUsers (ListBox1) End If End Sub' more vb.net source code and examples Please note that summary >''username param >' 'returned true, otherwise return falsereturns >' 'remarks > Private Function AddUser (ByVal username As String) As Boolean Try' to determine whether the user exists If (IsUserExists (username)) Then MsgBox ("user already exists, please enter another user!") Return False End If 'create user key KeyUsers.CreateSubKey (username, _ RegistryKeyPermissionCheck.ReadWriteSubTree)' re-list ListAllUsers (ListBox1) Catch ex As Exception Return False End Try End Function Private Sub btnCreateKey_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateKey.Click Dim key As RegistryKey Dim mykey As RegistryKey 'first need to obtain the HKEY_CURRENT_USER\ Softwar subkey Set writable to True to ensure that writable key = My.Computer.Registry.CurrentUser.OpenSubKey ("Software", True) 'creates a subkey under HKEY_CURRENT_USER\ Softwar and returns the created subkey object mykey = key.CreateSubKey ("MyKey", RegistryKeyPermissionCheck.ReadWriteSubTree)' create the value and set the value of the content mykey.SetValue ("UserName", "Rui.Chen", RegistryValueKind.String) End Sub Private Sub ListBox1_SelectedIndexChanged (ByVal sender As System.Object) ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged If (ListBox1.SelectedIndex > = 0) Then btnDelete.Enabled = True Else btnDelete.Enabled = False End If End Sub Private Sub btnDelete_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click DeleteUser (ListBox1.SelectedItem.ToString ()) End Sub Private Sub btnCreate_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click If (TextBox1.Text ") Then AddUser (TextBox1.Text) End If End Sub Private Sub Form1_Load (ByVal sender As System.Object ByVal e As System.EventArgs) Handles MyBase.Load KeyUsers = My.Computer.Registry.CurrentUser.OpenSubKey ("Software\ MyKey", True) ListAllUsers (ListBox1) btnDelete.Enabled = False End Sub End Class Thank you for reading! This is the end of the article on "how VB.NET traverses registry keys". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.