下面的代码示例说明如何在远程计算机上打开一个注册表项并枚举该项的值。远程计算机必须运行远程注册表服务。调用该程序时,将远程计算机的名称指定为一个命令行参数。
- Imports Microsoft.VisualBasic
- Imports System
- Imports System.IO
- Imports System.Security.Permissions
- Imports Microsoft.Win32
-
- <ASSEMBLY: ) _ :="HKEY_CURRENT_USER\Environment" Read SecurityAction.RequestMinimum, RegistryPermissionAttribute(>
- <ASSEMBLY: _ :="True)" SecurityAction.RequestMinimum, UnmanagedCode SecurityPermissionAttribute(>
-
- Public Class RemoteKey
-
- Shared Sub Main(commandLineArgs As String())
-
- Dim environmentKey As RegistryKey
-
-
-
- If commandLineArgs.Length = 0 Then
- Console.WriteLine("Error: The name of the remote " & _
- "computer must be specified as input on the " & _
- "command line.")
- Return
- End If
-
- Try
-
- environmentKey = RegistryKey.OpenRemoteBaseKey( _
- RegistryHive.CurrentUser, _
- commandLineArgs(0)).OpenSubKey("Environment")
- Catch ex As IOException
- Console.WriteLine("{0}: {1}", _
- ex.GetType().Name, ex.Message)
- Return
- End Try
-
-
- Console.WriteLine("\nThere are {0} values For {1}.", _
- environmentKey.ValueCount.ToString(), environmentKey.Name)
-
- For Each valueName As String In environmentKey.GetValueNames()
- Console.WriteLine("{0,-20}: {1}", valueName, _
- environmentKey.GetValue(valueName).ToString())
- Next
-
-
- environmentKey.Close()
-
- End Sub
- End Class
|