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

Registry.Users Field

Contains information about the default user configuration. This field reads the Windows registry base key HKEY_USERS.

[Visual Basic]
Public Shared ReadOnly Users As RegistryKey
[C#]
public static readonly RegistryKey Users;
[C++]
public: static RegistryKey* Users;
[JScript]
public static var Users : RegistryKey;

Remarks

This key contains a branch for each user of the computer. The default configuration is supplied for new users on the local computer and for the default current user if the user has not changed preferences. Because Windows 98/ME also supports Registry.Users, applications can access the user-specific information the same way they do under Windows 2000. Each user's information is stored in a separate file, which can be stored locally or on a network server. Windows 98/ME can copy this file to the user's current system so that settings can move from one computer to another with the user.

Example

[Visual Basic, C#, C++] The following example demonstrates how to retrieve the subkeys of this key, and prints their names to the screen. Use the OpenSubKey method to create an instance of the particular subkey of interest. You can then use other operations in RegistryKey to manipulate that key.

[Visual Basic] 
Imports System
Imports Microsoft.Win32

Class Reg
    
    Public Shared Sub Main()
        
        ' Create a RegistryKey, which will access the HKEY_USERS
        ' key in the registry of this machine.
        Dim rk As RegistryKey = Registry.Users
        
        ' 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

[C#] 
using System;
using Microsoft.Win32;

class Reg {
    public static void Main() {

        // Create a RegistryKey, which will access the HKEY_USERS
        // key in the registry of this machine.
        RegistryKey rk = Registry.Users;

        // 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;
        }
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace Microsoft::Win32;

void PrintKeys(RegistryKey* rkey) {

    // Retrieve all the subkeys for the specified key.
    String* names[] = rkey->GetSubKeyNames();

    int icount = 0;

    Console::WriteLine(S"Subkeys of {0}", rkey->Name);
    Console::WriteLine(S"-----------------------------------------------");

    // Print the contents of the array to the console.
    System::Collections::IEnumerator* enum0 = names->GetEnumerator();
    while (enum0->MoveNext())
    {
        String* s = __try_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_USERS
    // key in the registry of this machine.
    RegistryKey* rk = Registry::Users;

    // Print out the keys.
    PrintKeys(rk);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Registry Class | Registry Members | Microsoft.Win32 Namespace

Show:
© 2015 Microsoft