注册表Demo
一、获取安装程序信息
#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的更多相关文章
- form注册表单圆角 demo
form注册表单圆角 <BODY> <div class="form"> <ul class="list"> <li& ...
- 弥补学生时代的遗憾~C#注册表情缘
记得当时刚接触C#的时候,喜欢编写各种小软件,而注册表系列和网络系列被当时的我认为大牛的必备技能.直到我研究注册表前一天我都感觉他是那么的高深. 今天正好有空,于是就研究了下注册表系列的操作,也随手封 ...
- delphi 注册表操作(读取、添加、删除、修改)完全手册
DELPHI VS PASCAL(87) 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创建和释放TRegistry对象 1.创建TRegistry对象.为了操 ...
- C#注册表
C#注册表情缘 记得当时刚接触C#的时候,喜欢编写各种小软件,而注册表系列和网络系列被当时的我认为大牛的必备技能.直到我研究注册表前一天我都感觉他是那么的高深. 今天正好有空,于是就研究了下注册表 ...
- Delphi的注册表操作
转帖:Delphi的注册表操作 2009-12-21 11:12:52 分类: Delphi的注册表操作 32位Delphi程序中可利用TRegistry对象来存取注册表文件中的信息. 一.创 ...
- Eclipse出错不断,注册表不能乱改
Eclipse打不开,始终报错,还能不能开心的敲代码了??? 首先说下造成我这个愚蠢错误的起源:电脑是win10系统,本来是可以正常使用的.某一天,我正在使用python,打开命令提示符,看见开头是中 ...
- 入侵检测中需要监控的注册表路径研究(Windows Registry Security Check)
1. Windows注册表简介 注册表(Registry,繁体中文版Windows称之为登录档)是Microsoft Windows中的一个重要的数据库,用于存储系统和应用程序的设置信息.早在Wind ...
- 【干货】从windows注册表读取重要信息-----这种技能非常重要,占电子取证的70%
也就是说,当我拿着U盘启动盘,从你电脑里面拷贝了注册表的几个文件,大部分数据就已经到我手中了.一起来感受一下吧. 来源:Unit 6: Windows File Systems and Registr ...
- 基于HTML5手机登录注册表单代码
分享一款基于HTML5手机登录注册表单代码.这是一款鼠标点击注册登录按钮弹出表单,适合移动端使用.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class=&qu ...
随机推荐
- Vue 初学笔记
1. 对 Vue 的理解 Vue.js 是一个以数据驱动和组件化的思想构建的 JavaScript MVVM 库,下载 Vue.js 后可以直接在html里引用,Vue 本身并不依赖 Node 运行. ...
- JavaScript(js)获取本周,本月,本季,本年,上月,上周,上季,去年,上二周,上二月的时间段的代码
function dateChange(name){ var beginTimeObject = document.getElementById("beginTime"); var ...
- 各个版本 Windows 10 系统中自带的 .NET Framework 版本
原文各个版本 Windows 10 系统中自带的 .NET Framework 版本 Windows 名称 Windows 版本 自带的 .NET Framework 版本 Windows 10 Oc ...
- Win32 Windows计划 十一年
一个.使用位图 1 位图 - 由图像上的各点的颜色被保存,生成对应的位图文件 栅格 - 保存图像可以理解为晶格 矢量图 - 能够理解为画图命令的保存 2 位图的使用 2.1 载入位图 LoadBitm ...
- 标准差standard deviation和标准错误standard error你能解释一下
by:ysuncn(欢迎转载,请注明原创信息) 什么是标准差(standard deviation)呢?依据国际标准化组织(ISO)的定义:标准差σ是方差σ2的正平方根:而方差是随机变量期望的二次偏差 ...
- Java 阅读TXT文件
public class GenCategoryAttrItemHandler { private final static String INPUT_FILE_PATH = "input/ ...
- 微信nodejs开发模块指南
1.微信消息处理 node-weixin-message wechat 2.微信加密 node-weixin-crypto wechat-crypto 3.微信支付 node-weixin-pay w ...
- 自定义 DependencyProperty 与 RoutedEvent
原文:自定义 DependencyProperty 与 RoutedEvent //自定义依赖属性 class MyBook : DependencyObject//依赖属性必须派生自Dependen ...
- CommandParameter binding Introduction:
Design Patterns SampleCode https://csharpdesignpatterns.codeplex.com/ DevExpress Support Center http ...
- NetCore 上传,断点续传,可支持流上传
之前公司要做一个断点续传的业务,找了许多都没有找到合适的,都是残次不全的,终于让我遇到一个基于百度的 webuploader 的断点续传.原作者: 断点续传(上传)( https://www.some ...