当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET RegistryKey.OpenSubKey方法代码示例

本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:Microsoft.Win32,代码行数:33,代码来源:RegistryKey.OpenSubKey

示例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
开发者ID:VB.NET开发者,项目名称:Microsoft.Win32,代码行数:60,代码来源:RegistryKey.OpenSubKey

输出:

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
开发者ID:VB程序员,项目名称:Microsoft.Win32,代码行数:31,代码来源:RegistryKey.OpenSubKey


注:本文中的Microsoft.Win32.RegistryKey.OpenSubKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。