Registry.CurrentUser 字段

定义

包含有关当前用户首选项的信息。 此字段读取 Windows 注册表基项 HKEY_CURRENT_USER。

public: static initonly Microsoft::Win32::RegistryKey ^ CurrentUser;
public static readonly Microsoft.Win32.RegistryKey CurrentUser;
 staticval mutable CurrentUser : Microsoft.Win32.RegistryKey
Public Shared ReadOnly CurrentUser As RegistryKey 

字段值

示例

以下示例演示如何检索此键的子项,并将其名称输出到屏幕。 OpenSubKey使用 方法创建感兴趣的特定子项的实例。 然后,可以使用 中的其他 RegistryKey 操作来操作该键。

using namespace System;
using namespace Microsoft::Win32;
void PrintKeys( RegistryKey ^ rkey )
{
   
   // Retrieve all the subkeys for the specified key.
   array<String^>^names = rkey->GetSubKeyNames();
   int icount = 0;
   Console::WriteLine( "Subkeys of {0}", rkey->Name );
   Console::WriteLine( "-----------------------------------------------" );
   
   // Print the contents of the array to the console.
   System::Collections::IEnumerator^ enum0 = names->GetEnumerator();
   while ( enum0->MoveNext() )
   {
      String^ s = safe_cast<String^>(enum0->Current);
      Console::WriteLine( s );
      
      // The following code puts a limit on the number
      // of keys displayed.  Comment it out to print the
      // complete list.
      icount++;
      if ( icount >= 10 )
            break;
   }
}

int main()
{
   
   // Create a RegistryKey, which will access the HKEY_CURRENT_USER
   // key in the registry of this machine.
   RegistryKey ^ rk = Registry::CurrentUser;
   
   // Print out the keys.
   PrintKeys( rk );
}
using System;
using Microsoft.Win32;

class Reg {
    public static void Main() {

        // Create a RegistryKey, which will access the HKEY_CURRENT_USER
        // key in the registry of this machine.
        RegistryKey rk = Registry.CurrentUser;

        // Print out the keys.
        PrintKeys(rk);
    }

    static void PrintKeys(RegistryKey rkey) {

        // Retrieve all the subkeys for the specified key.
        string [] names = rkey.GetSubKeyNames();

        int icount = 0;

        Console.WriteLine("Subkeys of " + rkey.Name);
        Console.WriteLine("-----------------------------------------------");

        // Print the contents of the array to the console.
        foreach (string s in names) {
            Console.WriteLine(s);

            // The following code puts a limit on the number
            // of keys displayed.  Comment it out to print the
            // complete list.
            icount++;
            if (icount >= 10)
                break;
        }
    }
}
Imports Microsoft.Win32

Class Reg
    
    Public Shared Sub Main()
        
        ' Create a RegistryKey, which will access the HKEY_CURRENT_USER
        ' key in the registry of this machine.
        Dim rk As RegistryKey = Registry.CurrentUser
        
        ' Print out the keys.
        PrintKeys(rk)
    End Sub    
    
    Shared Sub PrintKeys(rkey As RegistryKey)
        
        ' Retrieve all the subkeys for the specified key.
        Dim names As String() = rkey.GetSubKeyNames()
        
        Dim icount As Integer = 0
        
        Console.WriteLine("Subkeys of " & rkey.Name)
        Console.WriteLine("-----------------------------------------------")
        
        ' Print the contents of the array to the console.
        Dim s As String
        For Each s In  names
            Console.WriteLine(s)
            
            ' The following code puts a limit on the number
            ' of keys displayed.  Comment it out to print the
            ' complete list.
            icount += 1            
            If icount >= 10 Then
                Exit For
            End If
        Next s
    End Sub
End Class

注解

此密钥中存储的信息包括环境变量的设置以及有关程序组、颜色、打印机、网络连接和应用程序首选项的数据。 使用此键可以更轻松地建立当前用户的设置。 在此密钥中,软件供应商存储当前用户特定的首选项,以在其应用程序中使用。 例如,Microsoft 创建 HKEY_CURRENT_USER\Software\Microsoft 密钥供其应用程序使用,每个应用程序在 Microsoft 密钥下创建自己的子项。

适用于