RegistryKey.GetSubKeyNames 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取包含所有子機碼名稱的字串陣列。
public:
cli::array <System::String ^> ^ GetSubKeyNames();
public string[] GetSubKeyNames ();
member this.GetSubKeyNames : unit -> string[]
Public Function GetSubKeyNames () As String()
傳回
String[]
字串的陣列包含了目前機碼的子機碼名稱。
例外狀況
使用者沒有讀取機碼所需的使用權限。
正接受管理的 RegistryKey 已經關閉 (關閉的機碼無法存取)。
使用者沒有必要的登錄權限。
發生系統錯誤,例如,目前的機碼已經刪除。
範例
此程式代碼範例是提供給 類別之較大範例的 RegistryKey 一部分。
// 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() );
}
}
// 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());
}
}
}
' 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
備註
這個方法不會遞歸地尋找名稱。 它會傳回其呼叫來源基底層級的名稱。