Windows 7 64-bit recursive delete registry program that can be run

Source: Internet
Author: User

In order to complete a simple registry removal program, since I am Win7 64-bit OS, write the following code to recursively delete the registry key values, the program code is as follows:

#include <tchar.h> #include <afx.h> #define Key_wow64_64key 256long deletesubkeytree (HKEY HKEY, LPCTSTR Lpsubkey) {LONG lResult; HKEY Hsubkey;dword dwindex, CBName; Char szsubkey[512]; FILETIME ft; LResult = RegOpenKeyEx (hkey,lpsubkey,0,key_all_access | Key_wow64_64key,&hsubkey); if (lResult! = ERROR_SUCCESS) {RegCloseKey (hsubkey); return 0;} dwindex = 0;cbname = sizeof (Szsubkey)/sizeof (szsubkey[0]); while (error_success = = (LResult = RegEnumKeyEx (Hsubkey), Dwindex, Szsubkey, &cbname, NULL, NULL, NULL, &FT))) {Deletesubkeytree (Hsubkey, Szsubkey);} RegCloseKey (hsubkey); lResult = Regdeletekey (HKey, Lpsubkey); return lResult;} int main () {LPCTSTR deletetext = _t ("software\\bentley\\licensing");    Deletesubkeytree (Hkey_local_machine,deletetext);:: MessageBox (NULL, _t ("cracked successfully! ")," ", MB_OK);    return 0;}

found that the key value exists, in the call RegQueryValueEx always query failure, returned 0, always thought to be the issue of permissions, to upgrade it to debug or not, the network also has a friend said to create. mainfest file elevation, later on the MSDN Web also found the relevant instructions. But it still failed. Put this program into XP and Win7 32 can be read out of the value of the normal. So I think it would be a 64-bit OS problem? Finally, Microsoft's latest MSDN online found the answer. It turns out that operating in the 64-bit OS registry must be aware of setting a value. First in the file header definition:

#define KEY_WOW64_64KEY 256//compatible with 64-bit host

Then add the parameters of the RegOpenKeyEx

key_all_access| key_wow64_64key,  //All access rights

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.