本文整理匯總了VB.NET中Microsoft.Win32.RegistryKey.OpenSubKey方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET RegistryKey.OpenSubKey方法的具體用法?VB.NET RegistryKey.OpenSubKey怎麽用?VB.NET RegistryKey.OpenSubKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.OpenSubKey方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports Microsoft.Win32
Public Class Example
Public Shared Sub Main()
' Delete and recreate the test key.
Registry.CurrentUser.DeleteSubKey("RegistryOpenSubKeyExample", False)
Dim rk As RegistryKey = Registry.CurrentUser.CreateSubKey("RegistryOpenSubKeyExample")
rk.Close
' Obtain an instance of RegistryKey for the CurrentUser registry
' root.
Dim rkCurrentUser As RegistryKey = Registry.CurrentUser
' Obtain the test key (read-only) and display it.
Dim rkTest As RegistryKey = rkCurrentUser.OpenSubKey("RegistryOpenSubKeyExample")
Console.WriteLine("Test key: {0}", rkTest)
rkTest.Close
rkCurrentUser.Close
' Obtain the test key in one step, using the CurrentUser registry
' root.
rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample")
Console.WriteLine("Test key: {0}", rkTest)
rkTest.Close
' Obtain the test key in read/write mode.
rkTest = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample", True)
rkTest.SetValue("TestName", "TestValue")
Console.WriteLine("Test value for TestName: {0}", rkTest.GetValue("TestName"))
rkTest.Close
End Sub
End Class
示例2: Example
' 導入命名空間
Imports Microsoft.Win32
Imports System.Diagnostics
Public Class Example
Public Shared Sub Main()
Const LIMIT As Integer = 100
Dim cu As RegistryKey = Registry.CurrentUser
Const testKey As String = "RegistryKeyPermissionCheckExample"
Console.WriteLine("Generating {0} key/value pairs.", LIMIT)
Dim rk As RegistryKey = cu.CreateSubKey(testKey)
For i As Integer = 0 To LIMIT
rk.SetValue("Key" & i, i)
Next i
rk.Close()
Dim s As New Stopwatch()
' On the default setting, security is checked every time
' a key/value pair is read.
rk = cu.OpenSubKey(testKey, _
RegistryKeyPermissionCheck.Default)
s.Start()
For i As Integer = 0 To LIMIT
rk.GetValue("Key" & i, i)
Next i
s.Stop()
rk.Close()
Dim delta1 As Long = s.ElapsedTicks
s.Reset()
' When the key is opened with ReadSubTree, security is
' not checked when the values are read.
rk = cu.OpenSubKey(testKey, _
RegistryKeyPermissionCheck.ReadSubTree)
s.Start()
For i As Integer = 0 To LIMIT
rk.GetValue("Key" & i, i)
Next i
s.Stop()
rk.Close()
Dim delta2 As Long = s.ElapsedTicks
Dim faster As Double = _
CDbl(delta1 - delta2) * 100.0 / CDbl(delta1)
Console.WriteLine("ReadSubTree is {0}% faster for {1} values.", _
faster.ToString("0.0"), LIMIT)
cu.DeleteSubKey(testKey)
End Sub
End Class
輸出:
Generating 100 key/value pairs. ReadSubTree is 23.4% faster for 100 values.
示例3: Main
' 導入命名空間
Imports System
Imports Microsoft.win32
Imports System.Diagnostics
Imports System.Windows.Forms
Public Class Tester
Public Shared Sub Main
Dim m_LM As RegistryKey
Dim m_HW As RegistryKey
Dim m_Des As RegistryKey
Dim m_System As RegistryKey
Dim m_CPU As RegistryKey
Dim m_Info As RegistryKey
m_LM = Registry.LocalMachine
m_HW = m_LM.OpenSubKey("HARDWARE")
m_Des = m_HW.OpenSubKey("DESCRIPTION")
m_System = m_Des.OpenSubKey("SYSTEM")
m_CPU = m_System.OpenSubKey("CentralProcessor")
m_Info = m_CPU.OpenSubKey("0")
Console.WriteLine(m_Info.GetValue("VendorIdentifier"))
Console.WriteLine(m_Info.GetValue("ProcessorNameString"))
Console.WriteLine(m_Info.GetValue("Identifier"))
Console.WriteLine(m_Info.GetValue("~Mhz") & "MHz")
End Sub
End Class