Enumerate all subkey names under a specified key

Source: Internet
Author: User

The following is a complete executable program in VC:

# Include "stdafx. H"
# Include <stdio. h>
# Include <windows. h>

# Define softpath "software // Microsoft // windows // CurrentVersion // Uninstall"

// Function: Lists All subkey names under a specified key.
Boolmyenumkey (lptstrszkeypath)
{
Hkey;
Long result;

// Open the Registry
Result =: regopenkeyex (HKEY_LOCAL_MACHINE, szkeypath, 0, key_read, & hkey );

If (result! = Error_success)
{
Returnfalse;
}

Tcharszkey [max_path];
Lptstrlpname = szkey;
Dworddwindex = 0; // incremental index used for listing

While (1)
{
Memset (szkey, 0, sizeof (szkey ));
// Lists all the subkeys under a specified key. lpname is used to receive the subkey name.
Result = regenumkey (hkey, dwindex ++, lpname, max_path + 1 );

If (result = error_no_more_items)
{
Break; // All subkeys have been listed
}

If (result! = Error_success)
{
Break;
}

// Display
Printf ("% 03d: keyname = % S/R/N", dwindex, szkey );
}

// Close the registry
: Regclosekey (hkey );
Returntrue;
}

Intmain (intargc, char * argv [])
{
Myenumkey (softpath );

Getchar ();

Return0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.