C++訪問(wèn)注冊(cè)表獲取已安裝軟件信息列表示例代碼
// ---------------------------------------------------------------
// FlieNmae:
// SofInfo.h
// Remark:
// 通過(guò)讀取注冊(cè)表獲得本機(jī)已安裝軟件信息。
// ---------------------------------------------------------------
#pragma once
#include <vector>
struct SoftInfo
{
// 軟件名
CString m_strSoftName;
// 軟件版本號(hào)
CString m_strSoftVersion;
// 軟件安裝目錄
CString m_strInstallLocation;
// 軟件發(fā)布廠商
CString m_strPublisher;
// 主程序所在完整路徑
CString m_strMainProPath;
// 卸載exe所在完整路徑
CString m_strUninstallPth;
};
class CSoftInfo
{
private:
// 保存已安裝常用軟件安裝信息
std::vector<SoftInfo> m_SoftInfoArr;
// 保存系統(tǒng)補(bǔ)丁信息
std::vector<SoftInfo> m_SystemPatchesArr;
public:
CSoftInfo();
~CSoftInfo(){}
// 獲取一個(gè)包含常用軟件安裝信息的Vector
std::vector<SoftInfo> GetSoftInfo (void) const;
// 獲取所有已安裝常用軟件名
void GetSoftName (std::vector<LPCTSTR>& lpszSoftName);
// 獲取所有已安裝常用軟件版本號(hào)
void GetSoftVersion (std::vector<LPCTSTR>& lpszSoftVersion);
// 獲取所有已安裝常用軟件安裝目錄
void GetInstallLocation (std::vector<LPCTSTR>& lpszInstallLocation);
// 獲取所有已安裝常用軟件發(fā)布廠商
void GetPublisher (std::vector<LPCTSTR>& lpszPublisher);
// 獲取所有已安裝常用軟件主程序所在路徑
void GetMainProPath (std::vector<LPCTSTR>& lpszMainProPath);
// 獲取所有已安裝常用軟件卸載程序所在路徑
void GetUninstallPth (std::vector<LPCTSTR>& lpszSoftName);
// 獲取一個(gè)包含系統(tǒng)補(bǔ)丁信息的Vector
std::vector<SoftInfo> GetSystemPatchesInfo (void) const;
// 獲取所有已安裝系統(tǒng)補(bǔ)丁名
void GetSystemPatchesName (std::vector<LPCTSTR>& lpszSoftName);
};
// FlieNmae: Softinfo.cpp
#include "stdafx.h"
#include "SoftInfo.h"
CSoftInfo::CSoftInfo()
{
struct SoftInfo softinfo;
HKEY RootKey; // 主鍵
LPCTSTR lpSubKey; // 子鍵名稱
HKEY hkResult; // 將要打開(kāi)鍵的句柄
HKEY hkRKey;
LONG lReturn; // 記錄讀取注冊(cè)表是否成功
CString strBuffer;
CString strMidReg;
DWORD index = 0;
TCHAR szKeyName[255] = {0}; // 注冊(cè)表項(xiàng)名稱
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("打開(kāi)注冊(cè)表失敗!"), 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++)
{
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++)
{
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++)
{
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;
// 初步去重復(fù)廠商
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++)
{
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);
}
}
上一篇:C語(yǔ)言切割多層字符串(strtok_r strtok使用方法)
欄 目:C語(yǔ)言
下一篇:C++設(shè)計(jì)類(lèi)不能被繼承的方法實(shí)例講解
本文標(biāo)題:C++訪問(wèn)注冊(cè)表獲取已安裝軟件信息列表示例代碼
本文地址:http://www.jygsgssxh.com/a1/Cyuyan/3884.html
您可能感興趣的文章
- 04-02c語(yǔ)言沒(méi)有round函數(shù) round c語(yǔ)言
- 01-10深入理解C++中常見(jiàn)的關(guān)鍵字含義
- 01-10使用C++實(shí)現(xiàn)全排列算法的方法詳解
- 01-10c++中inline的用法分析
- 01-10用C++實(shí)現(xiàn)DBSCAN聚類(lèi)算法
- 01-10全排列算法的非遞歸實(shí)現(xiàn)與遞歸實(shí)現(xiàn)的方法(C++)
- 01-10C++大數(shù)模板(推薦)
- 01-10淺談C/C++中的static與extern關(guān)鍵字的使用詳解
- 01-10深入C/C++浮點(diǎn)數(shù)在內(nèi)存中的存儲(chǔ)方式詳解
- 01-10深入理解C/C++混合編程


閱讀排行
- 1C語(yǔ)言 while語(yǔ)句的用法詳解
- 2java 實(shí)現(xiàn)簡(jiǎn)單圣誕樹(shù)的示例代碼(圣誕
- 3利用C語(yǔ)言實(shí)現(xiàn)“百馬百擔(dān)”問(wèn)題方法
- 4C語(yǔ)言中計(jì)算正弦的相關(guān)函數(shù)總結(jié)
- 5c語(yǔ)言計(jì)算三角形面積代碼
- 6什么是 WSH(腳本宿主)的詳細(xì)解釋
- 7C++ 中隨機(jī)函數(shù)random函數(shù)的使用方法
- 8正則表達(dá)式匹配各種特殊字符
- 9C語(yǔ)言十進(jìn)制轉(zhuǎn)二進(jìn)制代碼實(shí)例
- 10C語(yǔ)言查找數(shù)組里數(shù)字重復(fù)次數(shù)的方法
本欄相關(guān)
- 04-02c語(yǔ)言函數(shù)調(diào)用后清空內(nèi)存 c語(yǔ)言調(diào)用
- 04-02func函數(shù)+在C語(yǔ)言 func函數(shù)在c語(yǔ)言中
- 04-02c語(yǔ)言的正則匹配函數(shù) c語(yǔ)言正則表達(dá)
- 04-02c語(yǔ)言用函數(shù)寫(xiě)分段 用c語(yǔ)言表示分段
- 04-02c語(yǔ)言中對(duì)數(shù)函數(shù)的表達(dá)式 c語(yǔ)言中對(duì)
- 04-02c語(yǔ)言編寫(xiě)函數(shù)冒泡排序 c語(yǔ)言冒泡排
- 04-02c語(yǔ)言沒(méi)有round函數(shù) round c語(yǔ)言
- 04-02c語(yǔ)言分段函數(shù)怎么求 用c語(yǔ)言求分段
- 04-02C語(yǔ)言中怎么打出三角函數(shù) c語(yǔ)言中怎
- 04-02c語(yǔ)言調(diào)用函數(shù)求fibo C語(yǔ)言調(diào)用函數(shù)求
隨機(jī)閱讀
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 01-10C#中split用法實(shí)例總結(jié)
- 01-10SublimeText編譯C開(kāi)發(fā)環(huán)境設(shè)置
- 01-11Mac OSX 打開(kāi)原生自帶讀寫(xiě)NTFS功能(圖文
- 01-10使用C語(yǔ)言求解撲克牌的順子及n個(gè)骰子
- 01-11ajax實(shí)現(xiàn)頁(yè)面的局部加載
- 08-05DEDE織夢(mèng)data目錄下的sessions文件夾有什
- 08-05dedecms(織夢(mèng))副欄目數(shù)量限制代碼修改
- 08-05織夢(mèng)dedecms什么時(shí)候用欄目交叉功能?


