本文整理匯總了VB.NET中Microsoft.Win32.RegistryKey.GetValue方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET RegistryKey.GetValue方法的具體用法?VB.NET RegistryKey.GetValue怎麽用?VB.NET RegistryKey.GetValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Microsoft.Win32.RegistryKey
的用法示例。
在下文中一共展示了RegistryKey.GetValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
' 導入命名空間
Imports Microsoft.Win32
Public Class Example
Public Shared Sub Main()
' Delete and recreate the test key.
Registry.CurrentUser.DeleteSubKey("RegistryValueOptionsExample", False)
Dim rk As RegistryKey = _
Registry.CurrentUser.CreateSubKey("RegistryValueOptionsExample")
' Add a value that contains an environment variable.
rk.SetValue("ExpandValue", "The path is %PATH%", _
RegistryValueKind.ExpandString)
' Retrieve the value, first without expanding the environment
' variable and then expanding it.
Console.WriteLine("Unexpanded: ""{0}""", _
rk.GetValue("ExpandValue", "No Value", _
RegistryValueOptions.DoNotExpandEnvironmentNames))
Console.WriteLine("Expanded: ""{0}""", rk.GetValue("ExpandValue"))
End Sub
End Class
示例2: Example
' 導入命名空間
Imports Microsoft.Win32
Public Class Example
Public Shared Sub Main()
' Delete and recreate the test key.
Registry.CurrentUser.DeleteSubKey("RegistryValueKindExample", False)
Dim rk As RegistryKey = Registry.CurrentUser.CreateSubKey("RegistryValueKindExample")
' Create name/value pairs.
' This overload supports QWord (long) values.
rk.SetValue("QuadWordValue", 42, RegistryValueKind.QWord)
' The following SetValue calls have the same effect as using the
' SetValue overload that does not specify RegistryValueKind.
'
rk.SetValue("DWordValue", 42, RegistryValueKind.DWord)
rk.SetValue("MultipleStringValue", New String() {"One", "Two", "Three"}, RegistryValueKind.MultiString)
rk.SetValue("BinaryValue", New Byte() {10, 43, 44, 45, 14, 255}, RegistryValueKind.Binary)
rk.SetValue("StringValue", "The path is %PATH%", RegistryValueKind.String)
' This overload supports setting expandable string values. Compare
' the output from this value with the previous string value.
rk.SetValue("ExpandedStringValue", "The path is %PATH%", RegistryValueKind.ExpandString)
' Display all name/value pairs stored in the test key, with each
' registry data type in parentheses.
'
Dim valueNames As String() = rk.GetValueNames()
Dim s As String
For Each s In valueNames
Dim rvk As RegistryValueKind = rk.GetValueKind(s)
Select Case rvk
Case RegistryValueKind.MultiString
Dim values As String() = CType(rk.GetValue(s), String())
Console.Write(vbCrLf & " {0} ({1}) =", s, rvk)
For i As Integer = 0 To values.Length - 1
If i <> 0 Then Console.Write(",")
Console.Write(" ""{0}""", values(i))
Next i
Console.WriteLine()
Case RegistryValueKind.Binary
Dim bytes As Byte() = CType(rk.GetValue(s), Byte())
Console.Write(vbCrLf & " {0} ({1}) =", s, rvk)
For i As Integer = 0 To bytes.Length - 1
' Display each byte as two hexadecimal digits.
Console.Write(" {0:X2}", bytes(i))
Next i
Console.WriteLine()
Case Else
Console.WriteLine(vbCrLf & " {0} ({1}) = {2}", s, rvk, rk.GetValue(s))
End Select
Next s
End Sub
End Class
'
'This code example produces the following output (some output is omitted):
'
' QuadWordValue (QWord) = 42
'
' DWordValue (DWord) = 42
'
' MultipleStringValue (MultiString) = "One", "Two", "Three"
'
' BinaryValue (Binary) = 0A 2B 2C 2D 0E FF
'
' StringValue (String) = The path is %PATH%
'
' ExpandedStringValue (ExpandString) = The path is C:\Program Files\Microsoft.NET\SDK\v2.0\Bin;
' [***The remainder of this output is omitted.***]
示例3: RegGetDef
' 導入命名空間
Imports Microsoft.Win32
Public Class RegGetDef
Public Shared Sub Main()
' Create a reference to a valid key. In order for this code to
' work, the indicated key must have been created previously.
' The key name is not case-sensitive.
Dim rk As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\myTestKey", false)
' Get the value from the specified name/value pair in the key.
Dim valueName As String = "myTestValue"
Console.WriteLine("Retrieving registry value ...")
Console.WriteLine()
Dim o As Object = rk.GetValue(valueName)
Console.WriteLine("Object Type = " + o.GetType().FullName)
Console.WriteLine()
Select Case rk.GetValueKind(valueName)
Case RegistryValueKind.String
Case RegistryValueKind.ExpandString
Console.WriteLine("Value = " + o)
Case RegistryValueKind.Binary
For Each b As Byte In CType(o,Byte())
Console.Write("{0:x2} ", b)
Next b
Console.WriteLine()
Case RegistryValueKind.DWord
Console.WriteLine("Value = " + Convert.ToString(CType(o,Int32)))
Case RegistryValueKind.QWord
Console.WriteLine("Value = " + Convert.ToString(CType(o,Int64)))
Case RegistryValueKind.MultiString
For Each s As String In CType(o,String())
Console.Write("[{0:s}], ", s)
Next s
Console.WriteLine()
Case Else
Console.WriteLine("Value = (Unknown)")
End Select
' Attempt to retrieve a value that does not exist; the specified
' default value is returned.
Dim Def As String = rk.GetValue("notavalue", "The default to return")
Console.WriteLine()
Console.WriteLine(def)
rk.Close()
End Sub
End Class
'
' Output:
' Retrieving registry value ...
'
' Object Type = System.String
'
' Value = testData
'
'The default to return
示例4: 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