C + + Access Registry get installed software Information Column Presentation example code _c language

Source: Internet
Author: User



Copy Code code as follows:

// ---------------------------------------------------------------
Flienmae:
SofInfo.h
Remark:
Obtain the software information that is installed on this computer by reading the registry.
// ---------------------------------------------------------------
#pragma once
#include <vector>

struct SOFTINFO
{
Software name
CString M_strsoftname;
Software version number
CString m_strsoftversion;
Software Installation directory
CString m_strinstalllocation;
Software Publishing Vendors
CString M_strpublisher;
The full path of the main program
CString M_strmainpropath;
Uninstall EXE full path
CString m_struninstallpth;
};

Class Csoftinfo
{
Private
Save installed common Software installation information
Std::vector<softinfo> M_softinfoarr;
Save System Patch Information
Std::vector<softinfo> M_systempatchesarr;

Public
Csoftinfo ();
~csoftinfo () {}

Get a vector containing commonly used software installation information
Std::vector<softinfo> getsoftinfo (void) const;
Get all installed common software names
void Getsoftname (std::vector<lpctstr>& lpszsoftname);
Get all installed common software version numbers
void Getsoftversion (std::vector<lpctstr>& lpszsoftversion);
Get all installed common Software installation directory
void Getinstalllocation (std::vector<lpctstr>& lpszinstalllocation);
Get all installed common software publishing vendors
void Getpublisher (std::vector<lpctstr>& lpszpublisher);
Get the path to all installed common software main programs
void Getmainpropath (std::vector<lpctstr>& lpszmainpropath);
Get the path to all installed common software uninstall programs
void Getuninstallpth (std::vector<lpctstr>& lpszsoftname);

Gets a vector that contains system patch information
Std::vector<softinfo> getsystempatchesinfo (void) const;
Get all installed system patch names
void Getsystempatchesname (std::vector<lpctstr>& lpszsoftname);
};

Copy Code code as follows:

FlieNmae:Softinfo.cpp

#include "stdafx.h"
#include "SoftInfo.h"

Csoftinfo::csoftinfo ()
{
    struct softinfo softinfo;
    hkey rootkey;           //primary KEY
     LPCTSTR lpsubkey;       //Sub-key name
    hkey Hkresult ;           //The handle that will open the key
    hkey Hkrkey;
    LONG lreturn;           //Record Read Registry success
    CString Strbuffer;
    CString Strmidreg;

    DWORD index = 0;
    TCHAR szkeyname[255] = {0};       //registry key name
     TCHAR szbuffer[255] = {0};
    DWORD dwkeylen = 255;
    DWORD dwnamelen = 255;
    DWORD dwtype = reg_binary| reg_dword| reg_expand_sz| reg_multi_sz| reg_none| REG_SZ;
    rootkey = HKEY_LOCAL_MACHINE;
    Lpsubkey = _t ("Software\\microsoft\\windows\\currentversion\\uninstall");

    lreturn = RegOpenKeyEx (Rootkey, Lpsubkey, 0, key_all_access, &hkresult);

    if (lreturn = ERROR_SUCCESS)
    {

         while (Error_no_more_items!=regenumkeyex (Hkresult, Index, Szkeyname, &dwkeylen, 0, NULL, NULL, NULL)
        {
             index++;
            Strbuffer.format (_t ("%s"), szkeyname);
            if (!strbuffer.isempty ())
             {
                 Strmidreg = (CString) lpsubkey +_t ("\") + Strbuffer;

                if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, Strmidreg, 0, key_all_access, &hkrkey) ==error_success)
                 {
                     RegQueryValueEx (Hkrkey, _t ("DisplayName "), 0, &dwtype, (LPBYTE) szbuffer,&dwnamelen);
                     softinfo.m_strsoftname = szbuffer;
                     Dwnamelen = 255;
                     memset (szbuffer, 0, 255);

                     RegQueryValueEx (Hkrkey, _t ("DisplayVersion"), 0, &dwtype, (LPBYTE) szbuffer,&dwnamelen);
                     softinfo.m_strsoftversion = szbuffer;
                     Dwnamelen = 255;
                     memset (szbuffer, 0, 255);

                     RegQueryValueEx (Hkrkey, _t ("InstallLocation"), 0, &dwtype, (LPBYTE) szbuffer,&dwnamelen);
                     softinfo.m_strinstalllocation = szbuffer;
                     Dwnamelen = 255;
                     memset (szbuffer, 0, 255);

                     RegQueryValueEx (Hkrkey, _t ("Publisher"), 0, &dwtype, (LPBYTE) szbuffer,&dwnamelen);
                     softinfo.m_strpublisher = szbuffer;
                     Dwnamelen = 255;

RegQueryValueEx (Hkrkey, _t ("InstallLocation"), 0, &dwtype, (LPBYTE) szbuffer,&dwnamelen);
Softinfo.m_strmainpropath = Szbuffer;
Dwnamelen = 255;
memset (szbuffer, 0, 255);

RegQueryValueEx (Hkrkey, _t ("UninstallString"), 0, &dwtype, (LPBYTE) szbuffer,&dwnamelen);
Softinfo.m_struninstallpth = Szbuffer;
Dwnamelen = 255;
memset (szbuffer, 0, 255);

if (!softinfo.m_strsoftname.isempty ())
{
if (strbuffer.getat (0) = = ' K ' && strbuffer.getat (1) = = ' B ')
{
M_systempatchesarr.push_back (Softinfo);
}
Else
{
M_softinfoarr.push_back (Softinfo);
}
}
}

Dwkeylen = 255;
memset (szkeyname,0, 255);
}
}
RegCloseKey (Hkresult);
}
Else
{
:: MessageBox (NULL, _t ("Open Registry failed!"), null, mb_iconwarning);
}
}

Std::vector<softinfo> csoftinfo::getsoftinfo (void) const
{
return M_softinfoarr;
}

Void Csoftinfo::getsoftname (std::vector<lpctstr>& lpszsoftname)
{
    std:: Vector<softinfo>::iterator ITER;
    for (iter = M_softinfoarr.begin (); Iter!= m_softinfoarr.end (); iter++)
    { br>        Lpszsoftname.push_back (iter->m_strsoftname);
   }
}

Void Csoftinfo::getsoftversion (std::vector<lpctstr>& lpszsoftversion)
{
    std :: Vector<softinfo>::iterator iter;
    for (iter = M_softinfoarr.begin (); Iter!= m_softinfoarr.end (); iter++)
    { br>        if (!) ( iter->m_strsoftversion). IsEmpty ())
        {
             Lpszsoftversion.push_back (iter->m_strsoftversion);
       }
   }
}

Void Csoftinfo::getinstalllocation (std::vector<lpctstr>& lpszinstalllocation)
{
     Std::vector<softinfo>::iterator ITER;
    for (iter = M_softinfoarr.begin (); Iter!= m_softinfoarr.end (); iter++)
    { br>        if (!) ( iter->m_strinstalllocation). IsEmpty ())
        {
             Lpszinstalllocation.push_back (iter->m_strinstalllocation);
       }
   }
}

void Csoftinfo::getpublisher (std::vector<lpctstr>& lpszpublisher)
{
Std::vector<softinfo>::iterator ITER;

BOOL bsign;
for (iter = M_softinfoarr.begin (); Iter!= m_softinfoarr.end (); iter++)
{
Bsign = true;

Initial to repeat the manufacturer
Std::vector<lpctstr>::iterator ITR;
for (ITR = Lpszpublisher.begin (); ITR!= lpszpublisher.end (); itr++)
{
if (Iter->m_strpublisher = = (CString) *itr)
{
Bsign = false;
}
}

if (bsign)
{
Lpszpublisher.push_back (Iter->m_strpublisher);
}
}
}

Void Csoftinfo::getmainpropath (std::vector<lpctstr>& lpszmainpropath)
{
    std :: Vector<softinfo>::iterator iter;
    for (iter = M_softinfoarr.begin (); Iter!= m_softinfoarr.end (); iter++)
    { br>        if (!) ( Iter->m_strmainpropath). IsEmpty ())
        {
             Lpszmainpropath.push_back (Iter->m_strmainpropath);
       }
   }
}

void Csoftinfo::getuninstallpth (std::vector<lpctstr>& lpszsoftname)
{
Std::vector<softinfo>::iterator ITER;
for (iter = M_softinfoarr.begin (); Iter!= m_softinfoarr.end (); iter++)
{
if (!) ( iter->m_struninstallpth). IsEmpty ())
{
Lpszsoftname.push_back (iter->m_struninstallpth);
}
}
}

Std::vector<softinfo> csoftinfo::getsystempatchesinfo (void) const
{
return M_systempatchesarr;
}

void Csoftinfo::getsystempatchesname (std::vector<lpctstr>& lpszsoftname)
{
Std::vector<softinfo>::iterator ITER;
for (iter = M_systempatchesarr.begin (); Iter!= m_systempatchesarr.end (); iter++)
{
Lpszsoftname.push_back (Iter->m_strsoftname);
}
}

Related Article

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.