自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

講解VB.NET訪問注冊(cè)表方法

開發(fā) 后端
這里介紹VB.NET訪問注冊(cè)表變得非常的簡(jiǎn)單。我們可以用microsoft.Win32 名稱空間的下的registry類和registryKey類。另外My.Computer.Registry 也可以返回一個(gè)Microsoft.Win32.Registry類的實(shí)例。

本文向大家介紹VB.NET訪問注冊(cè)表,可能好多人還不了解VB.NET訪問注冊(cè)表,沒有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。

VB.NET訪問注冊(cè)表變得非常的簡(jiǎn)單。我們可以用microsoft.Win32 名稱空間的下的registry類和registryKey類。另外My.Computer.Registry 也可以返回一個(gè)Microsoft.Win32.Registry類的實(shí)例。

下面就舉幾個(gè)小例子來說明VB.NET訪問注冊(cè)表的方法。

1、返回或創(chuàng)建一個(gè)注冊(cè)表鍵

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

2、刪除注冊(cè)表鍵

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

3、創(chuàng)建或讀取注冊(cè)表項(xià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鍵,  
  5. 如果想創(chuàng)建項(xiàng),必須指定第二個(gè)參數(shù)為true  
  6. If Key2 Is Nothing Then  
  7. Key2 = Key1.CreateSubKey("northsnow") '如果鍵不存在就創(chuàng)建它  
  8. End If  
  9.  
  10. '創(chuàng)建項(xiàng),如果不存在就創(chuàng)建,如果存在則覆蓋  
  11. Key2.SetValue("name", "塞北的雪")  
  12. Key2.SetValue("sex", True)  
  13. Key2.SetValue("age", 30)  
  14. '返回項(xiàng)值  
  15. Dim sb As New System.Text.StringBuilder  
  16. sb.AppendLine(Key2.GetValue("name"))  
  17. sb.AppendLine(Key2.GetValue("sex"))  
  18. sb.AppendLine(Key2.GetValue("age"))  
  19. MsgBox(sb.ToString)  
  20. '查驗(yàn)?zāi)硞€(gè)項(xiàng)是否存在  
  21. If (Key2.GetValue("name")) Is Nothing Then  
  22. MsgBox("no")  
  23. Else  
  24. MsgBox("yes")  
  25. End If  
  26.  
  27. If (Key2.GetValue("name2")) Is Nothing Then  
  28. MsgBox("no")  
  29. Else  
  30. MsgBox("yes")  
  31. End If  
  32.  
  33. '輸出  
  34. ' 塞北的雪  
  35. 'True  
  36. '30  
  37. 'yes  
  38. 'no 

4、遍歷注冊(cè)表

這個(gè)也非常簡(jiǎn)單,在窗體上放一個(gè)按鈕和兩個(gè)文本框,添加如下的代碼:

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

【編輯推薦】

  1. 淺析VB.NET開發(fā)自動(dòng)分頁
  2. VB.NET ListView控件經(jīng)驗(yàn)總結(jié)
  3. 簡(jiǎn)單講述VB.NET讀取INI
  4. 簡(jiǎn)要介紹VB System.Array類及其成員
  5. 概括VB.NET獲取網(wǎng)卡地址的步驟
責(zé)任編輯:佚名 來源: IT168
相關(guān)推薦

2009-10-12 16:08:14

VB.NET訪問注冊(cè)表

2010-01-11 18:40:03

VB.NET操作注冊(cè)表

2009-11-10 17:31:38

VB.NET注冊(cè)表

2010-01-08 10:09:50

VB.NET注冊(cè)表操作

2009-10-26 14:50:18

VB.NET遍歷注冊(cè)表

2009-10-26 13:46:31

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

2010-01-18 13:57:38

VB.NET讀寫注冊(cè)表

2009-10-29 17:33:51

VB.NET線程方法

2010-01-11 16:04:10

VB.NET使用wit

2009-10-20 10:16:24

VB.NET COMB

2009-10-23 13:10:14

VB.NET List

2009-10-12 13:54:22

VB.NET Data

2009-10-15 11:42:05

VB.Net賦值語句

2010-01-12 16:30:21

VB.NET數(shù)據(jù)轉(zhuǎn)換

2009-10-13 14:38:10

VB.NET訪問類型

2009-10-14 17:21:47

VB.NET定制Win

2009-10-13 14:42:30

VB.NET靜態(tài)成員

2010-01-18 18:20:49

VB.NET使用API

2009-10-28 13:24:25

VB.NET文件

2010-01-14 15:44:17

VB.NET數(shù)據(jù)綁定
點(diǎn)贊
收藏

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