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

實(shí)例講解VB.NET訪問注冊表

開發(fā) 后端
這里介紹VB.NET訪問注冊表非常的簡單。我們可以用microsoft.Win32 名稱空間的下的registry類和registryKey類。

在向大家詳細(xì)介紹VB.NET訪問注冊表之前,首先讓大家了解下registry類和registryKey類,然后全面介紹VB.NET訪問注冊表。

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

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

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

  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  

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  

3.創(chuàng)建或讀取注冊表項(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.  
  6. 如果想創(chuàng)建項(xiàng),必須指定第二個(gè)參數(shù)為true  
  7. If Key2 Is Nothing Then  
  8. Key2 = Key1.CreateSubKey("northsnow") '如果鍵不存在就創(chuàng)建它  
  9. End If  
  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. If (Key2.GetValue("name2")) Is Nothing Then  
  27. MsgBox("no")  
  28. Else  
  29. MsgBox("yes")  
  30. End If 

4.遍歷注冊表

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

以上介紹VB.NET訪問注冊表。

【編輯推薦】

  1. 淺談VB.NET線程構(gòu)造器
  2. 簡單分析VB.NET使用線程
  3. VB.NET List(T)編寫框架方法
  4. 簡單介紹VB.NET線程同步
  5. VB.NET聲明API詳細(xì)描述
責(zé)任編輯:佚名 來源: IT168
相關(guān)推薦

2009-10-16 09:40:54

VB.NET訪問注冊表

2010-01-11 18:40:03

VB.NET操作注冊表

2010-01-08 10:09:50

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-14 16:54:56

VB.NET Impo

2010-01-11 16:04:10

VB.NET使用wit

2009-10-20 10:16:24

VB.NET COMB

2009-10-13 14:42:30

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

2009-10-14 17:21:47

VB.NET定制Win

2010-01-18 18:20:49

VB.NET使用API

2011-08-04 11:11:59

2009-10-12 13:54:22

VB.NET Data

2009-10-23 13:10:14

VB.NET List

2009-10-15 11:42:05

VB.Net賦值語句

2009-10-10 17:06:09

VB和VB.NET

2010-01-19 18:24:29

VB.NET調(diào)用Win

2009-10-13 14:38:10

VB.NET訪問類型
點(diǎn)贊
收藏

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