本文整理汇总了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