RegistryKey RegistryKey RegistryKey RegistryKey Class

定義

表示 Windows 登錄中的機碼層級節點。Represents a key-level node in the Windows registry. 這個類別的作用是登錄封裝。This class is a registry encapsulation.

public ref class RegistryKey sealed : MarshalByRefObject, IDisposable
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class RegistryKey : MarshalByRefObject, IDisposable
type RegistryKey = class
    inherit MarshalByRefObject
    interface IDisposable
Public NotInheritable Class RegistryKey
Inherits MarshalByRefObject
Implements IDisposable
繼承
屬性
實作

範例

下列程式碼範例示範如何建立在 HKEY_CURRENT_USER 下的子機碼、 操作其內容,然後再刪除子機碼。The following code example shows how to create a subkey under HKEY_CURRENT_USER, manipulate its contents, and then delete the subkey.

using namespace System;
using namespace System::Security::Permissions;
using namespace Microsoft::Win32;

int main()
{
   // Create a subkey named Test9999 under HKEY_CURRENT_USER.
   RegistryKey ^ test9999 = Registry::CurrentUser->CreateSubKey( "Test9999" );

   // Create two subkeys under HKEY_CURRENT_USER\Test9999.
   test9999->CreateSubKey( "TestName" )->Close();
   RegistryKey ^ testSettings = test9999->CreateSubKey( "TestSettings" );

   // Create data for the TestSettings subkey.
   testSettings->SetValue( "Language", "French" );
   testSettings->SetValue( "Level", "Intermediate" );
   testSettings->SetValue( "ID", 123 );
   testSettings->Close();

   // Print the information from the Test9999 subkey.
   Console::WriteLine( "There are {0} subkeys under Test9999.", test9999->SubKeyCount.ToString() );
   array<String^>^subKeyNames = test9999->GetSubKeyNames();
   for ( int i = 0; i < subKeyNames->Length; i++ )
   {
      RegistryKey ^ tempKey = test9999->OpenSubKey( subKeyNames[ i ] );
      Console::WriteLine( "\nThere are {0} values for {1}.", tempKey->ValueCount.ToString(), tempKey->Name );
      array<String^>^valueNames = tempKey->GetValueNames();
      for ( int j = 0; j < valueNames->Length; j++ )
      {
         Console::WriteLine( "{0,-8}: {1}", valueNames[ j ], tempKey->GetValue( valueNames[ j ] )->ToString() );

      }
   }
   
   // Delete the ID value.
   testSettings = test9999->OpenSubKey( "TestSettings", true );
   testSettings->DeleteValue( "id" );

   // Verify the deletion.
   Console::WriteLine( dynamic_cast<String^>(testSettings->GetValue(  "id", "ID not found." )) );
   testSettings->Close();

   // Delete or close the new subkey.
   Console::Write( "\nDelete newly created registry key? (Y/N) " );
   if ( Char::ToUpper( Convert::ToChar( Console::Read() ) ) == 'Y' )
   {
      Registry::CurrentUser->DeleteSubKeyTree( "Test9999" );
      Console::WriteLine( "\nRegistry key {0} deleted.", test9999->Name );
   }
   else
   {
      Console::WriteLine( "\nRegistry key {0} closed.", test9999->ToString() );
      test9999->Close();
   }
}
using System;
using System.Security.Permissions;
using Microsoft.Win32;

class RegKey
{
    static void Main()
    {
        // Create a subkey named Test9999 under HKEY_CURRENT_USER.
        RegistryKey test9999 = 
            Registry.CurrentUser.CreateSubKey("Test9999");
        // Create two subkeys under HKEY_CURRENT_USER\Test9999. The
        // keys are disposed when execution exits the using statement.
        using(RegistryKey 
            testName = test9999.CreateSubKey("TestName"),
            testSettings = test9999.CreateSubKey("TestSettings"))
        {
            // Create data for the TestSettings subkey.
            testSettings.SetValue("Language", "French");
            testSettings.SetValue("Level", "Intermediate");
            testSettings.SetValue("ID", 123);
        }

        // Print the information from the Test9999 subkey.
        Console.WriteLine("There are {0} subkeys under {1}.", 
            test9999.SubKeyCount.ToString(), test9999.Name);
        foreach(string subKeyName in test9999.GetSubKeyNames())
        {
            using(RegistryKey 
                tempKey = test9999.OpenSubKey(subKeyName))
            {
                Console.WriteLine("\nThere are {0} values for {1}.", 
                    tempKey.ValueCount.ToString(), tempKey.Name);
                foreach(string valueName in tempKey.GetValueNames())
                {
                    Console.WriteLine("{0,-8}: {1}", valueName, 
                        tempKey.GetValue(valueName).ToString());
                }
            }
        }

        using(RegistryKey 
            testSettings = test9999.OpenSubKey("TestSettings", true))
        {
            // Delete the ID value.
            testSettings.DeleteValue("id");

            // Verify the deletion.
            Console.WriteLine((string)testSettings.GetValue(
                "id", "ID not found."));
        }

        // Delete or close the new subkey.
        Console.Write("\nDelete newly created registry key? (Y/N) ");
        if(Char.ToUpper(Convert.ToChar(Console.Read())) == 'Y')
        {
            Registry.CurrentUser.DeleteSubKeyTree("Test9999");
            Console.WriteLine("\nRegistry key {0} deleted.", 
                test9999.Name);
        }
        else
        {
            Console.WriteLine("\nRegistry key {0} closed.", 
                test9999.ToString());
            test9999.Close();
        }
    }
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Security.Permissions
Imports Microsoft.Win32

Public Class RegKey
    Shared Sub Main()

        ' Create a subkey named Test9999 under HKEY_CURRENT_USER.
        Dim test9999 As RegistryKey = _
            Registry.CurrentUser.CreateSubKey("Test9999")

        ' Create two subkeys under HKEY_CURRENT_USER\Test9999.
        test9999.CreateSubKey("TestName").Close()
        Dim testSettings As RegistryKey = _
            test9999.CreateSubKey("TestSettings")

        ' Create data for the TestSettings subkey.
        testSettings.SetValue("Language", "French")
        testSettings.SetValue("Level", "Intermediate")
        testSettings.SetValue("ID", 123)
        testSettings.Close()

        ' Print the information from the Test9999 subkey.
        Console.WriteLine("There are {0} subkeys under Test9999.", _
            test9999.SubKeyCount.ToString())
        For Each subKeyName As String In test9999.GetSubKeyNames()
            Dim tempKey As RegistryKey = _
                test9999.OpenSubKey(subKeyName)
            Console.WriteLine(vbCrLf & "There are {0} values for " & _
                "{1}.", tempKey.ValueCount.ToString(), tempKey.Name)
            For Each valueName As String In tempKey.GetValueNames()
                Console.WriteLine("{0,-8}: {1}", valueName, _
                    tempKey.GetValue(valueName).ToString())
            Next
        Next

        ' Delete the ID value.
        testSettings = test9999.OpenSubKey("TestSettings", True)
        testSettings.DeleteValue("id")

        ' Verify the deletion.
        Console.WriteLine(CType(testSettings.GetValue( _
            "id", "ID not found."), String))
        testSettings.Close()

        ' Delete or close the new subkey.
        Console.Write(vbCrLf & "Delete newly created " & _
            "registry key? (Y/N) ")
        If Char.ToUpper(Convert.ToChar(Console.Read())) = "Y"C Then
            Registry.CurrentUser.DeleteSubKeyTree("Test9999")
            Console.WriteLine(vbCrLf & "Registry key {0} deleted.", _
                test9999.Name)
        Else
            Console.WriteLine(vbCrLf & "Registry key {0} closed.", _
                test9999.ToString())
            test9999.Close()
        End If
   
    End Sub
End Class

備註

若要取得的執行個體RegistryKey,使用其中一個靜態成員Registry類別。To get an instance of RegistryKey, use one of the static members of the Registry class.

登錄做為電腦上的作業系統和應用程式資訊的中央儲存機制。The registry acts as a central repository of information for the operating system and the applications on a computer. 登錄會組織成階層式的格式,並根據在其中儲存的項目邏輯順序 (請參閱Registry此階層中的基底層級項目)。The registry is organized in a hierarchical format, based on a logical ordering of the elements stored within it (please see Registry for the base-level items in this hierarchy). 時將資訊儲存在登錄中,選取要儲存的資訊類型為基礎的適當位置。When storing information in the registry, select the appropriate location based on the type of information being stored. 請務必避免破壞其他應用程式所建立,因為這可能會造成出現未預期的行為,這些應用程式,而且也可以有不利的影響,您自己的應用程式為基礎的資訊。Be sure to avoid destroying information created by other applications, because this can cause those applications to exhibit unexpected behavior, and can also have an adverse effect upon your own application.

重要

此類型會實作IDisposable介面。This type implements the IDisposable interface. 當您完成使用型別時,您應該處置它直接或間接。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接處置型別,呼叫其Dispose方法中的try / catch區塊。To dispose of the type directly, call its Dispose method in a try/catch block. 若要處置它間接,使用的語言建構這類using(在 C# 中) 或Using(在 Visual Basic)。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 如需詳細資訊,請參閱 「 使用物件,實作 IDisposable 」 一節IDisposable介面 > 主題。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

登錄機碼是在登錄中,組織的基本單位,並可以比喻為檔案總管 中的資料夾。Registry keys are the base unit of organization in the registry, and can be compared to folders in File Explorer. 特定的索引鍵可以有子機碼,就像資料夾可以有子資料夾。A particular key can have subkeys, just as a folder can have subfolders. 可以刪除每個索引鍵,只要使用者有適當的權限,若要這樣做,而且不是基底的索引鍵,或在正下方的基底的索引鍵層級。Each key can be deleted, as long as the user has the appropriate permissions to do so, and the key is not a base key or at the level directly under the base keys. 每個索引鍵也可以有多個與其相關聯 (值可以相較於檔案),這用來儲存資訊-例如,在電腦上安裝的應用程式的相關資訊的值。Each key can also have multiple values associated with it (a value can be compared to a file), which are used to store the information - for example, information about an application installed on the computer. 每個值會保留一段特定可以擷取或更新時所需的資訊。Each value holds one particular piece of information, which can be retrieved or updated when required. 比方說,您可以在其中建立RegistryKey貴公司,機碼 HKEY_LOCAL_MACHINE\Software,然後按一下 每個應用程式,您的公司建立子機碼。For instance, you can create a RegistryKey for your company, under the key HKEY_LOCAL_MACHINE\Software, and then a subkey for each application that your company creates. 每個子機碼保存的資訊,請在該應用程式,例如色彩設定畫面的位置和大小,特定或辨識副檔名。Each subkey holds the information specific to that application, such as color settings, screen location and size, or recognized file extensions.

請注意,儲存在登錄中的資訊可供其他應用程式和使用者,因此應該不會被用來儲存安全性資料或重要的應用程式資訊。Note that information stored in the registry is available to other applications and users, and therefore should not be used to store security data or critical application information.

警告

不會公開RegistryKey方式,一種惡意程式無法建立上千部無意義的子機碼或索引鍵/值組的物件。Do not expose RegistryKey objects in such a way that a malicious program could create thousands of meaningless subkeys or key/value pairs. 比方說,不允許呼叫者輸入任意索引鍵或值。For example, do not allow callers to enter arbitrary keys or values.

從開始.NET Framework 4.NET Framework 4,不再限制為 255 個字元的登錄機碼長度。Starting in the .NET Framework 4.NET Framework 4, the length of a registry key is no longer limited to 255 characters.

屬性

Handle Handle Handle Handle

取得SafeRegistryHandle物件,表示登錄機碼的目前RegistryKey物件會封裝。Gets a SafeRegistryHandle object that represents the registry key that the current RegistryKey object encapsulates.

Name Name Name Name

擷取機碼名稱。Retrieves the name of the key.

SubKeyCount SubKeyCount SubKeyCount SubKeyCount

擷取目前機碼中子機碼的計數。Retrieves the count of subkeys of the current key.

ValueCount ValueCount ValueCount ValueCount

擷取機碼中值的計數。Retrieves the count of values in the key.

View View View View

取得用來建立登錄機碼的檢視。Gets the view that was used to create the registry key.

方法

Close() Close() Close() Close()

如果其內容已經做了修改,請關閉機碼,並將它清除至磁碟中。Closes the key and flushes it to disk if its contents have been modified.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
CreateSubKey(String) CreateSubKey(String) CreateSubKey(String) CreateSubKey(String)

為寫入權限建立新的子機碼,或開啟現有的子機碼。Creates a new subkey or opens an existing subkey for write access.

CreateSubKey(String, Boolean) CreateSubKey(String, Boolean) CreateSubKey(String, Boolean) CreateSubKey(String, Boolean)

以指定權限建立新的子機碼,或開啟現有的子機碼。Creates a new subkey or opens an existing subkey with the specified access. 從 .NET Framework 4.6 開始可供使用。Available starting with .NET Framework 4.6.

CreateSubKey(String, Boolean, RegistryOptions) CreateSubKey(String, Boolean, RegistryOptions) CreateSubKey(String, Boolean, RegistryOptions) CreateSubKey(String, Boolean, RegistryOptions)

以指定權限建立新的子機碼,或開啟現有的子機碼。Creates a new subkey or opens an existing subkey with the specified access. 從 .NET Framework 4.6 開始可供使用。Available starting with .NET Framework 4.6.

CreateSubKey(String, RegistryKeyPermissionCheck) CreateSubKey(String, RegistryKeyPermissionCheck) CreateSubKey(String, RegistryKeyPermissionCheck) CreateSubKey(String, RegistryKeyPermissionCheck)

使用指定的權限檢查選項,為寫入權限建立新的子機碼,或開啟現有的子機碼。Creates a new subkey or opens an existing subkey for write access, using the specified permission check option.

CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions) CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions) CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions) CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions)

建立子機碼或開啟子機碼的寫入權限,使用指定的權限檢查和登錄選項。Creates a subkey or opens a subkey for write access, using the specified permission check and registry options.

CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity) CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity) CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity) CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity)

使用指定的權限檢查選項、登錄選項和登錄安全性,為寫入權限建立子機碼或開啟子機碼。Creates a subkey or opens a subkey for write access, using the specified permission check option, registry option, and registry security.

CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity) CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity) CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity) CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity)

使用指定的權限檢查選項和登錄安全性,為寫入權限建立新的子機碼,或開啟現有的子機碼。Creates a new subkey or opens an existing subkey for write access, using the specified permission check option and registry security.

DeleteSubKey(String) DeleteSubKey(String) DeleteSubKey(String) DeleteSubKey(String)

刪除指定的子機碼。Deletes the specified subkey.

DeleteSubKey(String, Boolean) DeleteSubKey(String, Boolean) DeleteSubKey(String, Boolean) DeleteSubKey(String, Boolean)

刪除指定的子機碼,並且指定在找不到該子機碼時是否引發例外狀況。Deletes the specified subkey, and specifies whether an exception is raised if the subkey is not found.

DeleteSubKeyTree(String) DeleteSubKeyTree(String) DeleteSubKeyTree(String) DeleteSubKeyTree(String)

遞迴地刪除子機碼和任何子系子機碼。Deletes a subkey and any child subkeys recursively.

DeleteSubKeyTree(String, Boolean) DeleteSubKeyTree(String, Boolean) DeleteSubKeyTree(String, Boolean) DeleteSubKeyTree(String, Boolean)

遞迴地刪除指定的子機碼和任何子系子機碼,並且指定在找不到該子機碼時是否引發例外狀況。Deletes the specified subkey and any child subkeys recursively, and specifies whether an exception is raised if the subkey is not found.

DeleteValue(String) DeleteValue(String) DeleteValue(String) DeleteValue(String)

從這個機碼中刪除指定值。Deletes the specified value from this key.

DeleteValue(String, Boolean) DeleteValue(String, Boolean) DeleteValue(String, Boolean) DeleteValue(String, Boolean)

刪除此機碼的指定值,並且指定找不到該值時是否引發例外狀況。Deletes the specified value from this key, and specifies whether an exception is raised if the value is not found.

Dispose() Dispose() Dispose() Dispose()

釋放 RegistryKey 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the RegistryKey class.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

關閉金鑰,並將它清除至磁碟的內容已經遭到修改。Closes the key and flushes it to disk if the contents have been modified.

Flush() Flush() Flush() Flush()

將指定的開啟登錄機碼的所有屬性 (Attribute) 寫入登錄中。Writes all the attributes of the specified open registry key into the registry.

FromHandle(SafeRegistryHandle) FromHandle(SafeRegistryHandle) FromHandle(SafeRegistryHandle) FromHandle(SafeRegistryHandle)

從指定的控制代碼建立登錄機碼。Creates a registry key from a specified handle.

FromHandle(SafeRegistryHandle, RegistryView) FromHandle(SafeRegistryHandle, RegistryView) FromHandle(SafeRegistryHandle, RegistryView) FromHandle(SafeRegistryHandle, RegistryView)

從指定的控制代碼和登錄檢視設定,建立登錄機碼。Creates a registry key from a specified handle and registry view setting.

GetAccessControl() GetAccessControl() GetAccessControl() GetAccessControl()

傳回目前登錄機碼的存取控制安全性。Returns the access control security for the current registry key.

GetAccessControl(AccessControlSections) GetAccessControl(AccessControlSections) GetAccessControl(AccessControlSections) GetAccessControl(AccessControlSections)

傳回目前登錄機碼之存取控制安全性的指定區段。Returns the specified sections of the access control security for the current registry key.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetSubKeyNames() GetSubKeyNames() GetSubKeyNames() GetSubKeyNames()

擷取包含所有子機碼名稱的字串陣列。Retrieves an array of strings that contains all the subkey names.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
GetValue(String) GetValue(String) GetValue(String) GetValue(String)

擷取與指定名稱關聯的值。Retrieves the value associated with the specified name. 傳回null如果不存在的名稱/值組,這是在登錄中。Returns null if the name/value pair does not exist in the registry.

GetValue(String, Object) GetValue(String, Object) GetValue(String, Object) GetValue(String, Object)

擷取與指定名稱關聯的值。Retrieves the value associated with the specified name. 如果找不到名稱,則傳回您提供的預設值。If the name is not found, returns the default value that you provide.

GetValue(String, Object, RegistryValueOptions) GetValue(String, Object, RegistryValueOptions) GetValue(String, Object, RegistryValueOptions) GetValue(String, Object, RegistryValueOptions)

擷取與指定名稱及擷取選項關聯的值。Retrieves the value associated with the specified name and retrieval options. 如果找不到名稱,則傳回您提供的預設值。If the name is not found, returns the default value that you provide.

GetValueKind(String) GetValueKind(String) GetValueKind(String) GetValueKind(String)

擷取與指定名稱關聯之值的登錄資料類型。Retrieves the registry data type of the value associated with the specified name.

GetValueNames() GetValueNames() GetValueNames() GetValueNames()

擷取包含所有與這個機碼相關值名稱的字串陣列。Retrieves an array of strings that contains all the value names associated with this key.

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OpenBaseKey(RegistryHive, RegistryView) OpenBaseKey(RegistryHive, RegistryView) OpenBaseKey(RegistryHive, RegistryView) OpenBaseKey(RegistryHive, RegistryView)

開啟新RegistryKey表示要求使用指定的檢視在本機電腦上的索引鍵。Opens a new RegistryKey that represents the requested key on the local machine with the specified view.

OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String) OpenRemoteBaseKey(RegistryHive, String)

開啟新RegistryKey表示要求機碼,在遠端電腦上的。Opens a new RegistryKey that represents the requested key on a remote machine.

OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView) OpenRemoteBaseKey(RegistryHive, String, RegistryView)

使用指定的檢視,開啟遠端電腦上表示要求機碼的新登錄機碼。Opens a new registry key that represents the requested key on a remote machine with the specified view.

OpenSubKey(String) OpenSubKey(String) OpenSubKey(String) OpenSubKey(String)

擷取子機碼為唯讀。Retrieves a subkey as read-only.

OpenSubKey(String, Boolean) OpenSubKey(String, Boolean) OpenSubKey(String, Boolean) OpenSubKey(String, Boolean)

擷取指定的子機碼,並且指定是否要套用至索引鍵的寫入權限。Retrieves a specified subkey, and specifies whether write access is to be applied to the key.

OpenSubKey(String, RegistryKeyPermissionCheck) OpenSubKey(String, RegistryKeyPermissionCheck) OpenSubKey(String, RegistryKeyPermissionCheck) OpenSubKey(String, RegistryKeyPermissionCheck)

擷取指定的子機碼,以供讀取或讀取/寫入存取。Retrieves the specified subkey for read or read/write access.

OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights) OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights) OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights) OpenSubKey(String, RegistryKeyPermissionCheck, RegistryRights)

擷取指定的子機碼以供讀取或讀取/寫入存取,並要求指定的存取權限。Retrieves the specified subkey for read or read/write access, requesting the specified access rights.

OpenSubKey(String, RegistryRights) OpenSubKey(String, RegistryRights) OpenSubKey(String, RegistryRights) OpenSubKey(String, RegistryRights)

擷取具有指定名稱和存取權限的子機碼。Retrieves a subkey with the specified name and access rights. 從 .NET Framework 4.6 開始可供使用。Available starting with .NET Framework 4.6.

SetAccessControl(RegistrySecurity) SetAccessControl(RegistrySecurity) SetAccessControl(RegistrySecurity) SetAccessControl(RegistrySecurity)

將 Windows 存取控制安全性套用至現有的登錄機碼。Applies Windows access control security to an existing registry key.

SetValue(String, Object) SetValue(String, Object) SetValue(String, Object) SetValue(String, Object)

設定指定的名稱/值組。Sets the specified name/value pair.

SetValue(String, Object, RegistryValueKind) SetValue(String, Object, RegistryValueKind) SetValue(String, Object, RegistryValueKind) SetValue(String, Object, RegistryValueKind)

使用指定的登錄資料類型,設定登錄機碼中名稱/值組的值。Sets the value of a name/value pair in the registry key, using the specified registry data type.

ToString() ToString() ToString() ToString()

擷取這個機碼的字串表示。Retrieves a string representation of this key.

明確介面實作

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

對目前的機碼執行 Close()Performs a Close() on the current key.

Extension Methods

GetAccessControl(RegistryKey) GetAccessControl(RegistryKey) GetAccessControl(RegistryKey) GetAccessControl(RegistryKey)
GetAccessControl(RegistryKey, AccessControlSections) GetAccessControl(RegistryKey, AccessControlSections) GetAccessControl(RegistryKey, AccessControlSections) GetAccessControl(RegistryKey, AccessControlSections)
SetAccessControl(RegistryKey, RegistrySecurity) SetAccessControl(RegistryKey, RegistrySecurity) SetAccessControl(RegistryKey, RegistrySecurity) SetAccessControl(RegistryKey, RegistrySecurity)

適用於

另請參閱