Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

RegistryKey.SubKeyCount Property

Retrieves the count of subkeys of the current key.

Namespace:  Microsoft.Win32
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Public ReadOnly Property SubKeyCount As Integer

Property Value

Type: System.Int32
The number of subkeys of the current key.

ExceptionCondition
SecurityException

The user does not have read permission for the key.

ObjectDisposedException

The RegistryKey being manipulated is closed (closed keys cannot be accessed).

UnauthorizedAccessException

The user does not have the necessary registry rights.

IOException

A system error occurred, for example the current key has been deleted.

This property does not recursively count names. It only returns the count of names on the base level from which it was called.

This code example is part of a larger example provided for the RegistryKey class.

' 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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Show:
© 2015 Microsoft