日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)C#.NET → VB.NET中快速訪問注冊表技巧

      VB.NET中快速訪問注冊表技巧

      相關(guān)軟件相關(guān)文章發(fā)表評論 來源:西西整理時間:2010/11/16 16:21:04字體大。A-A+

      作者:佚名點擊:69次評論:0次標簽: .NET

      .NETv3.0 可再發(fā)行組件包
      • 類型:編程輔助大。2.7M語言:中文 評分:1.8
      • 標簽:
      立即下載
      VB.NET中快速訪問注冊表技巧

        vb.net中訪問注冊表變得非常的簡單。我們可以用 microsoft.Win32 名稱空間的 下的 registry 類 和  registryKey 類!×硗狻y.Computer.Registry 也可以返回一個 Microsoft.Win32.Registry 類的實例。
      下面就舉幾個小例子來說明vb.net訪問注冊表的方法。

      1,返回或創(chuàng)建一個注冊表鍵

      Dim Key1 As Microsoft.Win32.RegistryKey
      Key1 = My.Computer.Registry.CurrentUser '返回當前用戶鍵
      Dim Key2 As Microsoft.Win32.RegistryKey
      Key2 = Key1.OpenSubKey("northsnow") '返回當前用戶鍵下的northsnow鍵
      If Key2 Is Nothing Then
      Key2 = Key1.CreateSubKey("northsnow") '如果鍵不存在就創(chuàng)建它
      End If

      2,刪除注冊表鍵
      Dim Key1 As Microsoft.Win32.RegistryKey
      Key1 = My.Computer.Registry.CurrentUser '返回當前用戶鍵
      Dim Key2 As Microsoft.Win32.RegistryKey

      Key2 = Key1.OpenSubKey("northsnow") '返回當前用戶鍵下的northsnow鍵
      If Not Key2 Is Nothing Then
      Key1.DeleteSubKey("northsnow") '如果鍵不存在就創(chuàng)建它
      End If
      3,創(chuàng)建或讀取注冊表項

      Dim Key1 As Microsoft.Win32.RegistryKey
      Key1 = My.Computer.Registry.CurrentUser '返回當前用戶鍵
      Dim Key2 As Microsoft.Win32.RegistryKey
      Key2 = Key1.OpenSubKey("northsnow", True) '返回當前用戶鍵下的northsnow鍵,如果想創(chuàng)建項,必須指定第二個參數(shù)為true
      If Key2 Is Nothing Then
      Key2 = Key1.CreateSubKey("northsnow") '如果鍵不存在就創(chuàng)建它
      End If

      '創(chuàng)建項,如果不存在就創(chuàng)建,如果存在則覆蓋
      Key2.SetValue("name", "塞北的雪")
      Key2.SetValue("sex", True)
      Key2.SetValue("age", 30)

      '返回項值
      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)

      '查驗?zāi)硞項是否存在
      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
      '輸出
      ' 塞北的雪
      'True
      '30
      'yes
      'no
      4,遍歷注冊表

      這個也非常簡單,在窗體上放一個按鈕和兩個文本框,添加如下的代碼

      Dim sb As New System.Text.StringBuilder '返回遍歷結(jié)果
      Dim sb2 As New System.Text.StringBuilder '返回讀取出錯的注冊表鍵
      Private Sub Button3_Click()Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      Dim Key1 As Microsoft.Win32.RegistryKey
      Key1 = My.Computer.Registry.CurrentUser '返回當前用戶鍵
      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
      '遍歷注冊表鍵樹
      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
      '遍歷某鍵下的項
      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

        相關(guān)評論

        閱讀本文后您有什么感想? 已有人給出評價!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評論

        最新評論

        發(fā)表評論 查看所有評論(0)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字數(shù): 0/500 (您的評論需要經(jīng)過審核才能顯示)