共用方式為


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 金鑰下建立自己的子機碼。

適用於