VC: Registry: Query and delete items (CRegKey Methods: Open, QueryValue,. DeleteValue, DeleteSubKey, RecurseDeleteKey)

Source: Internet
Author: User

// Registry Query
// 1
CRegKey regkey;
DWORD dValue;
LPCTSTR lp = "Console \\";
If (regkey. Open (HKEY_CURRENT_USER, lp) = ERROR_SUCCESS) // Open
{
If (regkey. QueryValue (dValue, "WindowSize") = ERROR_SUCCESS) // query
{
Cout <dValue <endl; // output the queried Value
}
Else
{
Cout <"Query Error" <endl;
}
Regkey. Close ();
}
Else
{
Cout <"Open error! "<Endl;
}

 

CRegKey regkey;

DWORD dwCount = 1024;

Char sValue [1024];

// LPCTSTR sValue; // The type of LPCTSTR is const and cannot be used.

LPCTSTR valueName = "";

LPCTSTR lpstr = "* \ shell \"; // you can only delete the key values under it.

If (regkey. Open (HKEY_CLASSES_ROOT, lpstr) = ERROR_SUCCESS) // Open

{

HKEY hKey;

// LPCTSTR hSubKey;

HKey = HKEY_CLASSES_ROOT;

// HSubKey = "* \ shell \ QQ \\";

: RegDeleteKey (hKey, lpstr );

: RegDeleteValue (hKey ,"");

 

Regkey. DeleteValue (""); // Delete the default value

// Note: regkey. DeleteValue (valuename );

// Regkey. DeleteSubKey ("command"); // You cannot delete an item that contains a subkey.

Regkey. RecurseDeleteKey ("QQ"); // Delete the item containing the subkey (QQ is the key name)

If (regkey. QueryValue (sValue, valueName, & dwCount) = ERROR_SUCCESS) //

{

Cout <sValue <endl; // output the queried Value

}

Else

{

Cout <"Query Error" <endl;

}

}

Else

{

Cout <"Open error! "<Endl;

}

Regkey. Close ();

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.