偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

VB.NET注冊表操作相關(guān)技巧解析

開發(fā) 后端
我們在這里為大家介紹的VB.NET注冊表操作方法主要是應(yīng)用VB.NET來對注冊表進(jìn)行訪問。我們可以通過本文內(nèi)容對此進(jìn)行詳細(xì)了解。

大家通過對VB.NET的學(xué)習(xí),可以知道,這款編程語言的應(yīng)用范圍是非常廣泛的。下面就一起來分析一下VB.NET注冊表操作的一些技巧。其實,VB.NET注冊表操作是非常的簡單。我們可以用 microsoft.Win32 名稱空間的 下的 registry 類 和  registryKey 類。 另外 My.Computer.Registry 也可以返回一個 Microsoft.Win32.Registry 類的實例。 #t#

下面就舉幾個小例子來說明VB.NET注冊表操作的方法。

VB.NET注冊表操作1,返回或創(chuàng)建一個注冊表鍵

 

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

 

VB.NET注冊表操作2,刪除注冊表鍵

  1. Dim Key1 As Microsoft.Win32.
    RegistryKey   
  2. Key1 = My.Computer.Registry.
    CurrentUser '返回當(dāng)前用戶鍵   
  3. Dim Key2 As Microsoft.Win32.
    RegistryKey   
  4. Key2 = Key1.OpenSubKey("northsnow") 
    '返回當(dāng)前用戶鍵下的northsnow鍵   
  5. If Not Key2 Is Nothing Then   
  6. Key1.DeleteSubKey("northsnow")
     '如果鍵不存在就創(chuàng)建它   
  7. End If  

VB.NET注冊表操作3,創(chuàng)建或讀取注冊表項

 

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

 

 

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

 

 

  1. '返回項值   
  2. Dim sb As New System.Text.StringBuilder   
  3. sb.AppendLine(Key2.GetValue("name"))   
  4. sb.AppendLine(Key2.GetValue("sex"))   
  5. sb.AppendLine(Key2.GetValue("age"))   
  6. MsgBox(sb.ToString)  

 

 

  1. '查驗?zāi)硞€項是否存在   
  2. If (Key2.GetValue("name")) 
    Is Nothing Then   
  3. MsgBox("no")   
  4. Else   
  5. MsgBox("yes")   
  6. End If  

 

  1. If (Key2.GetValue("name2")) 
    Is Nothing Then   
  2. MsgBox("no")   
  3. Else   
  4. MsgBox("yes")   
  5. End If   
  6. '輸出   
  7. ' 塞北的雪   
  8. 'True   
  9. '30   
  10. 'yes   
  11. 'no  

VB.NET注冊表操作4,遍歷注冊表

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

 

  1. Dim sb As New System.Text.StringBuilder 
    '返回遍歷結(jié)果   
  2. Dim sb2 As New System.Text.StringBuilder 
    '返回讀取出錯的注冊表鍵   
  3. Private Sub Button3_Click()Sub Button3_
    Click(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles 
    Button3.Click   
  4. Dim Key1 As Microsoft.Win32.RegistryKey   
  5. Key1 = My.Computer.Registry.CurrentUser 
    '返回當(dāng)前用戶鍵   
  6. If Not Key1 Is Nothing Then   
  7. sb.AppendLine(Key1.Name)   
  8. readValue(Key1)   
  9. readReg(Key1)   
  10. End If   
  11. Me.TextBox1.Text = sb.ToString   
  12. Me.TextBox2.Text = sb2.ToString   
  13. End Sub   
  14. '遍歷注冊表鍵樹   
  15. Private Sub readReg()Sub readReg
    (ByVal r As Microsoft.Win32.RegistryKey)   
  16. If r.SubKeyCount > 0 Then   
  17. Dim keyName() As String   
  18. Dim keyTemp As Microsoft.Win32.RegistryKey   
  19. keyName = r.GetSubKeyNames   
  20. Dim i As Integer   
  21. For i = 0 To keyName.GetLength(0) - 1   
  22. Try   
  23. sb.AppendLine(keyName(i))   
  24. keyTemp = r.OpenSubKey(keyName(i), True)   
  25. readValue(keyTemp)   
  26. readReg(keyTemp)   
  27. Catch ex As Exception   
  28. sb2.AppendLine(keyName(i))   
  29. End Try   
  30. Next   
  31. End If   
  32. End Sub   
  33. '遍歷某鍵下的項   
  34. Private Sub readValue()Sub readValue
    (ByVal r As Microsoft.Win32.RegistryKey)   
  35. If r.ValueCount > 0 Then   
  36. Dim valueName() As String   
  37. Dim i As Integer   
  38. valueName = r.GetValueNames   
  39. For i = 0 To valueName.GetLength(0) - 1   
  40. sb.AppendLine("####")   
  41. sb.Append(r.Name)   
  42. sb.Append("----")   
  43. sb.Append(r.GetValue(valueName(i))
    .ToString)   
  44. Next   
  45. End If   
  46. End Sub 

VB.NET注冊表操作的一些實際應(yīng)用技巧就為大家介紹到這里。

責(zé)任編輯:曹凱 來源: 博客園
相關(guān)推薦

2010-01-11 18:40:03

VB.NET操作注冊表

2009-10-12 16:08:14

VB.NET訪問注冊表

2009-10-16 09:40:54

VB.NET訪問注冊表

2009-11-10 17:31:38

VB.NET注冊表

2009-10-26 14:50:18

VB.NET遍歷注冊表

2010-01-18 13:57:38

VB.NET讀寫注冊表

2009-10-26 13:46:31

VB.NET注冊表權(quán)限

2010-01-13 10:25:30

VB.NET文件夾操作

2010-01-15 13:52:42

VB.NET屬性設(shè)置

2010-01-13 15:33:40

VB.NET菜單項目

2010-01-19 15:08:18

VB.NET對象成員

2010-01-15 19:04:09

2010-01-14 16:04:32

VB.NET顯示時間

2010-01-15 15:10:43

VB.NET Stri

2010-01-07 17:24:12

VB.NET連接數(shù)據(jù)庫

2010-01-08 14:07:47

VB.NET窗體傳值

2010-01-18 14:54:00

VB.NET共享成員變

2010-01-22 16:07:26

VB.NET Mid函

2009-11-02 10:30:37

VB.NET EXCE

2010-01-11 13:33:07

VB.NET使用數(shù)組
點贊
收藏

51CTO技術(shù)棧公眾號