VC reads the registry to obtain the installer

Source: Internet
Author: User

In Windows, the installer can be obtained in the Registry HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Uninstall, and XP, Vista, win7, and Win8 are the same.

Open the Registry command: regedit, and expand the above registry path in sequence. The list of installation programs is as follows:

 

Obtain the system installer list:

// Obtain the system installer list bool cmylistctrltestdlg: allregkey (hkey, lpctstr szdeskeyitem) {hkey hsubkey; DWORD dwindex = 0; long lresult; int I = 1; lresult = regopenkeyex (hkey, szdeskeyitem, 0, key_read, & hsubkey); // open the registry if (error_success = lresult) {tchar szkeyname [256] = {0 }; DWORD cbname = 256 * sizeof (tchar); lresult = regenumkeyex (hsubkey, dwindex, szkeyname, & cbname, 0, null); // get Field while (lresult = error_success & lresult! = Error_more_data) {outputdebugstring (szkeyname); cstring STR; Str. format (_ T ("% d"), I); I = m_mylist.insertitem (I, STR); // insert it to the list control to display m_mylist.setitemtext (I, 1, szkeyname ); dwindex = dwindex + 1; // change dwindex and obtain the cbname = 256 * sizeof (tchar); lresult = regenumkeyex (hsubkey, dwindex, szkeyname, & cbname, 0, null, null, null); I ++;} regclosekey (hsubkey); // disable registry return true;} regclosekey (hsubkey); Return false ;}

 
Get installer attributes(Read the registry twice ):

Bool softlist: allregkey (hkey, lpctstr szdeskeyitem) {hkey hsubkey; DWORD dwindex = 0; long lresult; lresult = Digest (hkey, szdeskeyitem, 0, key_read, & hsubkey ); // open the registry if (error_success = lresult) {int id = 1; // No. tchar s_name [256] = {0 }; // software name tchar s_displayname [256] = {0}; // display name tchar s_publisher [256] = {0}; // publisher tchar s_installdate [12] = {0 }; // installation date: DWORD s_estimatedsize; // tchar s_disp Layversion [256] = {0}; // DWORD cbname = 256 * sizeof (tchar); DWORD cbname2 = sizeof (tchar); DWORD typesz = REG_SZ; // SZ registry type DWORD typedword = REG_DWORD; // DWORD registry type lresult = regenumkeyex (hsubkey, dwindex, s_name, & cbname, 0, null, null ); // obtain the field while (lresult = error_success & lresult! = Error_more_data) {outputdebugstring (s_name); cstring STR; Str. format (_ T ("% d"), ID); Id = m_softlist.insertitem (ID, STR); // insert it to the list control to display m_softlist.setitemtext (ID, 1, s_name ); hkey hitem; // next-level registry handle if (: regopenkeyex (hsubkey, s_name, 0, key_read, & hitem) = error_success) {// extract the property information of the next-level Registry Program if (: regqueryvalueex (hitem, _ T ("displayname"), 0, & typesz, (lpbyte) s_displayname, & cbname) = error_success) {m_soft List. setitemtext (ID, 1, s_displayname);} If (: regqueryvalueex (hitem, _ T ("publisher"), 0, & typesz, (lpbyte) s_publisher, & cbname) = error_success) {m_softlist.setitemtext (ID, 2, s_publisher);} If (: regqueryvalueex (hitem, _ T ("installdate"), 0, & typesz, (lpbyte) s_installdate, & cbname) = error_success) {If (s_installdate! = NULL) {// determines whether it is null m_softlist.setitemtext (ID, 3, s_installdate) ;}} if (: regqueryvalueex (hitem, _ T ("estimatedsize"), 0, & typedword, (lpbyte) & s_estimatedsize, & cbname2) = error_success) {float f_size = s_estimatedsize/1024.0; // convert DWORD to cstring type cstring p_size; p_size.format (_ T ("%. 2f M "), f_size); m_softlist.setitemtext (ID, 4, p_size);} If (: regqueryvalueex (hitem, _ T (" displayversion "), 0, & typesz, (lpbyte) s_displayversion, & cbname) = error_success) {m_softlist.setitemtext (ID, 5, s_displayversion); }:: regclosekey (hitem ); // close the second-level registry (Program attribute information)} dwindex = dwindex + 1; // change dwindex and obtain the downward field cbname = 256 * sizeof (tchar) cyclically ); lresult = regenumkeyex (hsubkey, dwindex, s_name, & cbname, 0, null, null); Id ++;} regclosekey (hsubkey ); // close the first-level registry (read program information) return true;} regclosekey (hsubkey); Return false ;}

Call through the registry path:

AllRegKey(HKEY_LOCAL_MACHINE, TEXT("SoftWare\\Microsoft\\Windows\\CurrentVersion\\Uninstall"));

 

Running result:

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.