Windows下C编程获取软件安装列表信息
代码如下:
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;
#ifndef MSVCR
#define _T
#define _tcscpy strcpy
#define _stprintf sprintf
#define _tcscmp strcmp
#endif
typedef struct SetupSoftInfo
{
string displayName; //软件名称
string publisher; //发行商
string displayVersion; //版本
string installDate; //安装日期
string uninstallString; //卸载命令及参数
void show()
{
cout<<"\n=======================================================\n软件名称:"
<<displayName<<"\n发行商:"<<publisher<<"\n版本:"<<displayVersion
<<"\n安装日期:"<<installDate<<"\n卸载命令:"<<uninstallString<<endl;
}
}*PSetupSoftInfo;
BOOL GetSetupSofts(vector<SetupSoftInfo>&stupInfo)
{
const int MAX_LEG = 256 * sizeof(TCHAR);
HKEY hKey;
DWORD dwRegNum = MAX_LEG;
TCHAR regBufferName[MAX_LEG] = {0};
if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"),
NULL, KEY_READ, &hKey) == ERROR_SUCCESS ) {
if( RegQueryInfoKey(hKey, NULL, NULL, NULL, &dwRegNum, NULL, NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS ){
for( int i = 0; i < (int)dwRegNum; i++ ) {
DWORD dwRegSize = MAX_LEG;
RegEnumKeyEx(hKey, i, regBufferName, &dwRegSize, NULL, NULL,
NULL, NULL);
DWORD dwType;
HKEY hSubKey;
if( RegOpenKeyEx(hKey, regBufferName, NULL, KEY_READ, &hSubKey) == ERROR_SUCCESS)
{
SetupSoftInfo info;
TCHAR regBufferValue[MAX_LEG] = {0};
dwRegSize = MAX_LEG;
RegQueryValueEx(hSubKey, _T("DisplayName"), 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
info.displayName = regBufferValue; //软件名称
dwRegSize = MAX_LEG;
_tcscpy(regBufferValue,_T(""));
RegQueryValueEx(hSubKey, _T("Publisher"), 0, &dwType,(LPBYTE)regBufferValue, &dwRegSize);
info.publisher = regBufferValue; //发行商
dwRegSize = MAX_LEG;
_tcscpy(regBufferValue,_T(""));
RegQueryValueEx(hSubKey, _T("DisplayVersion"), 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
info.displayVersion = regBufferValue; //版本
dwRegSize = MAX_LEG;
_tcscpy(regBufferValue,_T(""));
// 判断是否能在注册表中获取到安装时间, 否取子项创建时间
if(RegQueryValueEx(hSubKey, _T("InstallDate"), 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize) == ERROR_SUCCESS )
{
info.installDate = regBufferValue;
}
else
{
FILETIME fileLastTime;
RegQueryInfoKey(hSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, &fileLastTime);
SYSTEMTIME sTime, stLocal ;
FileTimeToSystemTime(&fileLastTime,&sTime);
SystemTimeToTzSpecificLocalTime(NULL, &sTime, &stLocal);
TCHAR tchTime[MAX_LEG] = {0};
_stprintf(tchTime,_T("%d%02d%02d"),stLocal.wYear,stLocal.wMonth,stLocal.wDay);
info.installDate = tchTime;
}
dwRegSize = MAX_LEG;
_tcscpy(regBufferValue,_T(""));
RegQueryValueEx(hSubKey, _T("UninstallString"), 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
info.uninstallString = regBufferValue;//卸载命令及参数
dwRegSize = MAX_LEG;
_tcscpy(regBufferValue,_T(""));
// 取ParentKeyName键值,判断是否是补丁信息, 是补丁信息键值为"OperatingSystem"
RegQueryValueEx(hSubKey, _T("ParentKeyName"), 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
TCHAR tchLocal[MAX_LEG] = {0};
_tcscpy(tchLocal,regBufferValue);
_tcscpy(regBufferValue,_T(""));
dwRegSize = MAX_LEG;
RegQueryValueEx(hSubKey, _T("QuietUninstallString"), 0, &dwType, (LPBYTE)regBufferValue, &dwRegSize);
if( _tcscmp(regBufferValue,_T("") ) )
{
info.displayName = regBufferName;
info.uninstallString = regBufferValue;
}
if( (info.displayName != _T("") )
&&( _tcscmp( tchLocal,_T("OperatingSystem") ) )) //判断是否是补丁信息
{
stupInfo.push_back(info);
}
}
}//end for(; ;)
}
}else {
return FALSE; //打开键失败
}
RegCloseKey(hKey);
return TRUE;
}
int main()
{
cout << "开始输出!" << endl;
vector<SetupSoftInfo> stupInfo;
GetSetupSofts(stupInfo);
for(auto& x:stupInfo){
x.show();
}
return 0;
}
Windows下C编程获取软件安装列表信息的更多相关文章
- python获取软件安装列表2222
softer_installed_list ===================== 使用python编写的,获取本机软件安装列表,输出为html表格. * win7 32位环境下运行 * 使用的是 ...
- 初尝Windows 下批处理编程
本文叫“ 初尝Windows 下批处理编程”是为了延续上一篇“初尝 Perl”,其实对于博主而言批处理以及批处理编程早就接触过了. 本文包括以下内容 1.什么是批处理 2.常用批处理命令 3.简介批处 ...
- Windows下当地RabbitMQ服务的安装
Windows下本地RabbitMQ服务的安装 本文参考:刘若泽相关技术文档 当然这些内容页可以通过RabbitMQ官方网站获得. RabbitMQ配置说明手册 一.RaibbitMQ服务器配置 1. ...
- Windows下的lua-5.3.4安装过程
Windows下的lua-5.3.4安装过程 Mingw平台下的编译过程: $ make echo$ make mingw$ make local $ make echo PLAT= none CC= ...
- windows下python常用库的安装
windows下python常用库的安装,前提安装了annaconda 的python开发环境.只要已经安装了anaconda,要安装别的库就很简单了.只要使用pip即可,正常安装好python,都会 ...
- windows下使用cpanm进行模块安装
windows下使用cpanm进行模块安装 要放假了,突然想整理一下手头上的软件,突然发现perl的安装模块这个功能不能用. 弄了一下,使得windows 下 perl 的 cpanm能用,避免成天为 ...
- 初探WINDOWS下IME编程
初探WINDOWS下IME编程作者:广东南海市昭信科技有限公司-李建国 大家知道,DELPHI许多控件有IME属性.这么好用的东西VC可没自带,怎么办呢?其实,可通过注册表,用API实现.下面说一下本 ...
- Windows下cmd的替代软件——PowerCmd
Powercmd 是一款运行在windows下的cmd增强软件(A Better Command Prompt Replacement Tool),当前最新的版本为2.2. 官方提供试用版,貌似没有功 ...
- windows下配置lamp环境(1)---安装Apache服务器2.2.25
window下lamp成为wamp; 安装wamp环境的第一步是安装Apache服务器.下面开始安装步骤图文并茂. 一.双击安装包点“next”进行下一步,然后同意协议(这张图没有截):
随机推荐
- [LeetCode] Implement Queue using Stacks 用栈来实现队列
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...
- [LeetCode] Path Sum 二叉树的路径和
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- Python小白的发展之路之Python基础(二)
列表.元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表.元组操作 (1)列表 列表是可变的(mutable)--可以改变列表的内容,这不同于字符串和元组,字符串和元组都是不 ...
- 【CodeVS 1288】埃及分数
http://codevs.cn/problem/1288/ loli秘制面向高一的搜索,好难啊QAQ 我本来想按照分母从大到小搜,因为这样分母从小到大枚举到的第一个可行方案就是最优方案. 但貌似会T ...
- weui 搜索框
点击搜索,会显示关键字取消按钮,输入文字,会在搜索框下,有相应的列表显示. HTML: <!DOCTYPE html> <html> <head> <meta ...
- staxon实现json和xml互转
pom.xml: <dependency> <groupId>de.odysseus.staxon</groupId> <artifactId>stax ...
- Markdown
1. 斜体和粗体 代码: *斜体*或_斜体_ **粗体** ***加粗斜体*** ~~删除线~~ 显示效果: 这是一段斜体 这是一段粗体 这是一段加粗斜体 这是一段删除线 2. 分级标题 第一种写法: ...
- 并发包的线程池第二篇--Executors的构造
上一篇讲述了ThreadPoolExecutor的执行过程,我们也能看出来一个很明显的问题:这个线程池的构造函数比较复杂,对于不十分理解其运作原理的程序员,自己构造它可能体现和想象中不一样的行为.比如 ...
- 个人作业-Week3:代码复审
软件工程师的成长 我在上大学之前,对于软件工程师之类并无概念,并且高初中的电脑课也从未提及过写代码之类的东西,更多的都是一些教一些办公软件的使用(笑,明明电脑课总是因为老师“有事”变成其他课,根本就没 ...
- HDU 4081Qin Shi Huang's National Road System(次小生成树)
题目大意: 有n个城市,秦始皇要修用n-1条路把它们连起来,要求从任一点出发,都可以到达其它的任意点.秦始皇希望这所有n-1条路长度之和最短.然后徐福突然有冒出来,说是他有魔法,可以不用人力.财力就变 ...