一、获取安装程序信息

 #include <windows.h>
#include <iostream>
#include <string>
#include <vector> using namespace std; //记录安装软件信息的结构体
struct ApplicationInfoA
{
string strName; //软件名
string strDisplayName; //显示的软件名
string strPublisher; //发布者
string strVersion; //版本
string strDisPlayVersion; //显示的版本
string strInstallLocation; //安装的位置
}; int GetAppInfoA(HKEY hKey, LPCSTR lpszAppName, LPCSTR lpszKeyValueName, string &strKeyValue)
{
int iRet;
HKEY hInstallAppKey; iRet = RegOpenKeyExA(hKey, lpszAppName, , KEY_ALL_ACCESS, &hInstallAppKey);
if (iRet != ERROR_SUCCESS)
{
return -;
} DWORD dwKeyValueType = REG_SZ;
DWORD dwKeyValueDataSize = ; iRet = RegQueryValueExA(hInstallAppKey, lpszKeyValueName, NULL, &dwKeyValueType, NULL, &dwKeyValueDataSize);
if (iRet == ERROR_FILE_NOT_FOUND)
{
RegCloseKey(hInstallAppKey);
return ;
}
else if (iRet != ERROR_SUCCESS)
{
RegCloseKey(hInstallAppKey);
return -;
} if (dwKeyValueType != REG_SZ)
{
RegCloseKey(hInstallAppKey);
return ;
} LPSTR lpszKeyValueData = new char[dwKeyValueDataSize + ];
memset(lpszKeyValueData, , dwKeyValueDataSize + ); iRet = RegQueryValueExA(hInstallAppKey, lpszKeyValueName, NULL, &dwKeyValueType, (LPBYTE)lpszKeyValueData, &dwKeyValueDataSize);
if (iRet != ERROR_SUCCESS)
{
delete []lpszKeyValueData;
RegCloseKey(hInstallAppKey);
return -;
} strKeyValue = lpszKeyValueData;
delete []lpszKeyValueData;
RegCloseKey(hInstallAppKey); return ;
} int GetAllInstalledAppInfoA(vector<ApplicationInfoA> &vecAppInfo)
{
int iRet;
HKEY hKey;
LPCSTR lpszSubKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
iRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpszSubKey, , KEY_ALL_ACCESS, &hKey);
if (iRet != ERROR_SUCCESS)
{
return -;
} DWORD dwSubKeysCnt;
DWORD dwMaxSubKeyNameLen;
DWORD dwKeyValueCnt;
DWORD dwMaxKeyValueNameLen;
DWORD dwMaxKeyValueDataLen; iRet = RegQueryInfoKeyA(
hKey,
NULL,
NULL,
NULL,
&dwSubKeysCnt,
&dwMaxSubKeyNameLen,
NULL,
&dwKeyValueCnt,
&dwMaxKeyValueNameLen,
&dwMaxKeyValueDataLen,
NULL,
NULL);
if (iRet != ERROR_SUCCESS)
{
RegCloseKey(hKey);
return -;
} DWORD dwIndex;
DWORD dwNameLen = dwMaxSubKeyNameLen + ;
LPSTR lpszSubKeyName = new char[dwNameLen]; for (dwIndex = ; dwIndex < dwSubKeysCnt; ++dwIndex)
{
dwNameLen = dwMaxSubKeyNameLen + ;
memset(lpszSubKeyName, , dwNameLen); iRet = RegEnumKeyExA(hKey, dwIndex, lpszSubKeyName, &dwNameLen, NULL, NULL, NULL, NULL);
if (iRet != ERROR_SUCCESS)
{
RegCloseKey(hKey);
delete []lpszSubKeyName;
return -;
} ApplicationInfoA appInfo;
appInfo.strName = lpszSubKeyName;
GetAppInfoA(hKey, lpszSubKeyName, "DisplayName", appInfo.strDisplayName);
GetAppInfoA(hKey, lpszSubKeyName, "Publisher", appInfo.strPublisher);
GetAppInfoA(hKey, lpszSubKeyName, "Version", appInfo.strVersion);
GetAppInfoA(hKey, lpszSubKeyName, "DisplayVersion", appInfo.strDisPlayVersion);
GetAppInfoA(hKey, lpszSubKeyName, "InstallLocation", appInfo.strInstallLocation);
vecAppInfo.push_back(appInfo);
} delete []lpszSubKeyName;
RegCloseKey(hKey); return ;
} int main(int argc, char **argv)
{
cout << "Application Information" << endl; vector<ApplicationInfoA> vecAppInfo;
cout << GetAllInstalledAppInfoA(vecAppInfo) << endl; for (vector<ApplicationInfoA>::const_iterator iter = vecAppInfo.begin(); iter != vecAppInfo.end(); ++iter)
{
cout << "-------------------------------------------------------------------------------" << endl;
cout << "Name:" << iter->strName << endl;
cout << "DisplayName:" << iter->strDisplayName << endl;
cout << "Publisher:" << iter->strPublisher << endl;
cout << "Version:" << iter->strVersion << endl;
cout << "DisplayVersion:" << iter->strDisPlayVersion << endl;
cout << "InstallLocation:" << iter->strInstallLocation << endl;
cout << "-------------------------------------------------------------------------------" << endl;
cout << endl;
cout << endl;
} return ;
}

二、添加环境变量

 #define _CRT_SECURE_NO_WARNINGS

 #include <windows.h>
#include <iostream>
#include <string> using namespace std; int AddPathEnvValue(LPCSTR lpszPathValue)
{
int iRet;
HKEY hKey;
LPCSTR lpszSubKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment"; iRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, lpszSubKey, , KEY_ALL_ACCESS, &hKey);
if (ERROR_SUCCESS != iRet)
{
cout << "RegOpenKeyExA Error!" << endl;
return -;
} LPCSTR lpszKeyValueName = "Path";
DWORD dwKeyValueType = REG_EXPAND_SZ;
DWORD dwKeyValueDataSize = ; iRet = RegQueryValueExA(hKey, lpszKeyValueName, NULL, &dwKeyValueType, NULL, &dwKeyValueDataSize);
if (ERROR_FILE_NOT_FOUND != iRet)
{
iRet = RegSetValueExA(hKey, lpszKeyValueName, , REG_EXPAND_SZ, (const BYTE*)"", );
if (ERROR_SUCCESS != iRet)
{
cout << "RegSetValueExA Error!" << endl;
RegCloseKey(hKey);
return -;
}
}
else if (ERROR_SUCCESS != iRet)
{
cout << "RegSetValueExA Error!" << endl;
RegCloseKey(hKey);
return -;
}
else if (REG_EXPAND_SZ != dwKeyValueType)
{
cout << "It is impossible!" << endl;
cout << dwKeyValueType << endl;
RegCloseKey(hKey);
return -;
} char *lpszKeyValueData = new char[dwKeyValueDataSize + ];
memset(lpszKeyValueData, , dwKeyValueDataSize + ); iRet = RegQueryValueExA(hKey, lpszKeyValueName, NULL, &dwKeyValueType, (LPBYTE)lpszKeyValueData, &dwKeyValueDataSize);
if (ERROR_SUCCESS != iRet)
{
cout << "RegQueryValueExA Error!" << endl;
RegCloseKey(hKey);
delete []lpszKeyValueData;
return -;
} unsigned int iLen = strlen(lpszPathValue);
iLen += strlen(lpszKeyValueData);
char *lpszKeyValueData_New = new char[iLen + ];
memset(lpszKeyValueData_New, , iLen + );
sprintf(lpszKeyValueData_New, "%s%s", lpszKeyValueData, lpszPathValue);
iRet = RegSetValueExA(hKey, lpszKeyValueName, , REG_EXPAND_SZ, (const BYTE*)lpszKeyValueData_New, iLen + );
if (ERROR_SUCCESS != iRet)
{
cout << "RegSetValueExA Error!" << endl;
RegCloseKey(hKey);
delete []lpszKeyValueData;
delete []lpszKeyValueData_New;
return -;
} delete []lpszKeyValueData_New;
delete []lpszKeyValueData; RegCloseKey(hKey); return ;
} int main(int argc, char *argv)
{
cout << AddPathEnvValue(";HelloKitty") << endl;
return ;
}

注册表Demo的更多相关文章

  1. form注册表单圆角 demo

    form注册表单圆角 <BODY> <div class="form"> <ul class="list"> <li& ...

  2. 弥补学生时代的遗憾~C#注册表情缘

    记得当时刚接触C#的时候,喜欢编写各种小软件,而注册表系列和网络系列被当时的我认为大牛的必备技能.直到我研究注册表前一天我都感觉他是那么的高深. 今天正好有空,于是就研究了下注册表系列的操作,也随手封 ...

  3. delphi 注册表操作(读取、添加、删除、修改)完全手册

    DELPHI VS PASCAL(87)  32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...

  4. C#注册表

    C#注册表情缘   记得当时刚接触C#的时候,喜欢编写各种小软件,而注册表系列和网络系列被当时的我认为大牛的必备技能.直到我研究注册表前一天我都感觉他是那么的高深. 今天正好有空,于是就研究了下注册表 ...

  5. Delphi的注册表操作

    转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息.     一.创 ...

  6. Eclipse出错不断,注册表不能乱改

    Eclipse打不开,始终报错,还能不能开心的敲代码了??? 首先说下造成我这个愚蠢错误的起源:电脑是win10系统,本来是可以正常使用的.某一天,我正在使用python,打开命令提示符,看见开头是中 ...

  7. 入侵检测中需要监控的注册表路径研究(Windows Registry Security Check)

    1. Windows注册表简介 注册表(Registry,繁体中文版Windows称之为登录档)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息.早在Wind ...

  8. 【干货】从windows注册表读取重要信息-----这种技能非常重要,占电子取证的70%

    也就是说,当我拿着U盘启动盘,从你电脑里面拷贝了注册表的几个文件,大部分数据就已经到我手中了.一起来感受一下吧. 来源:Unit 6: Windows File Systems and Registr ...

  9. 基于HTML5手机登录注册表单代码

    分享一款基于HTML5手机登录注册表单代码.这是一款鼠标点击注册登录按钮弹出表单,适合移动端使用.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class=&qu ...

随机推荐

  1. MapReduce 经典案例手机流量排序的分析

    在进行流量排序之前,先要明白排序是发生在map阶段,排序之后(排序结束后map阶段才会显示100%完成)才会到reduce阶段(事实上reduce也会排序),.此外排序之前要已经完成了手机流量的统计工 ...

  2. 不要完全相信Chrome控制台打印的信息

    以下两张图,第一张是Chrome控制台Network里请求返回的信息,图二是在代码里在请求返回的处理第一行代码用console.log打印的信息. 图一 图二 那么问题来了,为何通过console.l ...

  3. Lettcode_104_Maximum Depth of Binary Tree

    本文研究的总结,欢迎转载,但请注明出处:http://blog.csdn.net/pistolove/article/details/41964475 Maximum Depth of Binary ...

  4. 基于go语言的心跳响应

    我们在使用tcp ip 通讯的时候,都需要使用心跳机制来判断服务器与客户端的连接状态,如果服务器的心跳超时等,会做出重新连接等机制, 基于这种问题,我今天给大家推荐了一个基于go语言的心跳响应机制,废 ...

  5. Logistic Regression 的简单推导

    Logistic Regression 是一种 Generalized Linear Model(GLM),也即广义线性模型. 1. LR 的基本假设 LR 模型假设观测值 y 成立的对数几率(log ...

  6. 各个版本 Windows 10 系统中自带的 .NET Framework 版本

    原文各个版本 Windows 10 系统中自带的 .NET Framework 版本 Windows 名称 Windows 版本 自带的 .NET Framework 版本 Windows 10 Oc ...

  7. openresty: nginx worker不同请求之间共享数据

    To globally share data among all the requests handled by the same nginx worker process, encapsulate ...

  8. Linux下编译,要下载tar.xz,而不要下载zip,因为换行的编码不一样,对.h.cpp没有影响,但是对脚本有影响 good

    原因是 在win下编辑的时候,换行结尾是\n\r , 而在linux下 是\n,所以才会有 多出来的\r但是这个我是直接下载的官网文件解压的,没有动过啊. 破案了. linux下编译要下 .tar.x ...

  9. σ 代数与测度(measures)

    1. definition Let A be a collection of subsets(集合的集合体,collection of subsets) of a sample space Ω,A i ...

  10. 学术研究中的 NLP

    1. baseline 流程化的处理方式, 用 BoW 将 sentences 从 text 表示成 vector, LR 或者 SVM 做回归: LIBLINEAR – A Library for ...