次の方法で共有


RegistryKey.OpenSubKey メソッド (String, Boolean)

指定したサブキーを取得します。

Overloads Public Function OpenSubKey( _
   ByVal name As String, _   ByVal writable As Boolean _) As RegistryKey
[C#]
public RegistryKey OpenSubKey(stringname,boolwritable);
[C++]
public: RegistryKey* OpenSubKey(String* name,boolwritable);
[JScript]
public function OpenSubKey(
   name : String,writable : Boolean) : RegistryKey;

パラメータ

  • name
    開くサブキーの名前またはパス。
  • writable
    キーへの書き込みアクセスが必要な場合には true に設定してください。

戻り値

要求されたサブキー。操作が失敗した場合は null。

例外

例外の種類 条件
ArgumentNullException name が null です。
ArgumentException 指定したサブキーの長さが、許容される最大値 (255 文字) を超えています。
ObjectDisposedException 削除対象の RegistryKey が閉じています。閉じられたキーにはアクセスできません。
SecurityException このユーザーには、RegistryPermission.SetInclude(delete, currentKey) アクセス許可がありません。

解説

要求されたキーが存在しない場合、例外はスローされず、null 値が返されます。

writable が true の場合、キーは読み書きできる状態で開かれます。それ以外の場合、キーは読み取り専用で開かれます。

使用例

[Visual Basic, C#, C++] 次のコード例は RegistryKey クラスの例の一部です。

 
' Delete the non-secure password value.
testSettings = test9999.OpenSubKey("TestSettings", True)
testSettings.DeleteValue("password")

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

[C#] 
using(RegistryKey 
    testSettings = test9999.OpenSubKey("TestSettings", true))
{
    // Delete the non-secure password value.
    testSettings.DeleteValue("password");

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

[C++] 
// Delete the non-secure password value.
testSettings = test9999->OpenSubKey(S"TestSettings", true);
testSettings->DeleteValue(S"password");

// Verify the deletion.
Console::WriteLine(dynamic_cast<String*>(
    testSettings->GetValue("password", S"Password not found.")));
testSettings->Close();

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

  • RegistryPermission (指定したレジストリ キーを読み取るために必要なアクセス許可) Read (関連する列挙体)
  • SecurityPermission (指定したレジストリ キーがリモート キーである場合にアンマネージ コードにアクセスするために必要なアクセス許可) UnmanagedCode (関連する列挙体)

参照

RegistryKey クラス | RegistryKey メンバ | Microsoft.Win32 名前空間 | RegistryKey.OpenSubKey オーバーロードの一覧 | CreateSubKey | DeleteSubKey | DeleteSubKeyTree | GetSubKeyNames | OpenRemoteBaseKey | SubKeyCount | Registry