当前位置:网站首页>Modify registry values
Modify registry values
2022-04-23 06:43:00 【The old man is outside the door】
#include<iostream>
#include <string>
#include <vector>
#include <windows.h>
#include <wincrypt.h>
#include <Windows.h>
#include <iostream>
#include "shellapi.h"
#include <locale>
#include <codecvt>
#include<string>
#include <direct.h>
#include <olectl.h>
#include <io.h>
#include<fstream>
#include <atlstr.h>
#include <regex>
using namespace std;
#pragma warning(disable:4996)
#pragma comment(lib, "oleaut32.lib")
#pragma comment(lib, "VERSION.lib")
#pragma comment(lib, "crypt32.lib")
#define ENCODING (X509_ASN_ENCODING | PKCS_7_ASN_ENCODING)
int WChar2AChar(const WCHAR* lpstr, char** pOut, UINT type)
{
int count = wcslen(lpstr);
if (pOut == NULL || count == 0)
return 0;
int nACharCount = ::WideCharToMultiByte(type, 0, lpstr, -1, NULL, 0, NULL, NULL);
*pOut = new char[nACharCount];
memset(*pOut, 0, sizeof(char) * (nACharCount));
int result = ::WideCharToMultiByte(type, 0, lpstr, -1, *pOut, nACharCount, NULL, NULL);
if (*pOut == NULL || result > nACharCount)
{
return 0;
}
return nACharCount;
}
CString string2CString(std::string csStrData)
{
int lengthOfWcs1 = MultiByteToWideChar(CP_UTF8, 0, csStrData.c_str(), -1, NULL, 0);
wchar_t* wcs1 = new wchar_t[lengthOfWcs1 + 1];
MultiByteToWideChar(CP_UTF8, 0, csStrData.c_str(), -1, wcs1, lengthOfWcs1);
char* pOut = nullptr;
int n = WChar2AChar(wcs1, &pOut, CP_ACP);
if (pOut)
{
CString strRet(pOut);
delete[] wcs1;
wcs1 = NULL;
delete[] pOut;
pOut = nullptr;
return strRet;
}
delete[] wcs1;
wcs1 = NULL;
return "";
}
std::string CString2string(CString csStrData)
{
int lengthOfWcs1 = MultiByteToWideChar(CP_ACP, 0, csStrData, -1, NULL, 0);
wchar_t* wcs1 = new wchar_t[lengthOfWcs1 + 1];
MultiByteToWideChar(CP_ACP, 0, csStrData, -1, wcs1, lengthOfWcs1);
char* pOut = nullptr;
int n = WChar2AChar(wcs1, &pOut, CP_UTF8);
if (pOut)
{
std::string strRet = std::string(pOut);
delete[] wcs1;
wcs1 = NULL;
delete[] pOut;
pOut = nullptr;
return strRet;
}
delete[] wcs1;
wcs1 = NULL;
return "";
}
bool SetRegeditValue(std::string load, int Judge,std::string key,std::string value)
{
HKEY hKEY;
HKEY hKEYResult;
HKEY newKEY;
char dtchData[512];// Store string
DWORD etchData = 0;// Store numbers
DWORD dwValueType;
long lRet;// Record the return value of the function to facilitate debugging
DWORD dwSize;
DWORD dwType = REG_DWORD;
TCHAR szKeyName[255] = {
0 };// Registry key name
DWORD index = 0;
DWORD dwKeyLen = 255;
std::string strBuffer;
std::string strMidReg;
int ret = -1;
std::string data_Set;// Registry operation path for example
data_Set += load;
if (Judge == 1) {
lRet = RegOpenKeyExA(HKEY_LOCAL_MACHINE, data_Set.c_str(), 0, KEY_WOW64_64KEY | KEY_READ, &hKEY);
}
else {
lRet = RegOpenKeyExA(HKEY_CURRENT_USER, data_Set.c_str(), 0, KEY_WOW64_64KEY | KEY_READ, &hKEY);
}
if (ERROR_SUCCESS == lRet) {
while (ERROR_NO_MORE_ITEMS != RegEnumKeyEx(hKEY, index, szKeyName, &dwKeyLen, 0, NULL, NULL, NULL)) {
index++;
strBuffer += CString2string(szKeyName);
if (!strBuffer.empty())
{
long temp = -1;
strMidReg += data_Set;
strMidReg += "\\";
strMidReg += strBuffer;
strMidReg = string2CString(strMidReg);
//printf("strMidReg %s\n", strMidReg);
if (Judge == 1) {
temp = RegOpenKeyExA(HKEY_LOCAL_MACHINE, strMidReg.c_str(), 0, KEY_WOW64_64KEY | KEY_READ, &hKEYResult);
}
else {
temp = RegOpenKeyExA(HKEY_CURRENT_USER, strMidReg.c_str(), 0, KEY_WOW64_64KEY | KEY_READ, &hKEYResult);
}
if (temp == ERROR_SUCCESS)
{
//DisplayIcon
dwSize = 512;
RegQueryValueExA(hKEYResult, "DisplayIcon", 0, &dwValueType, (LPBYTE)dtchData, &dwSize);
std::string dispalyIcon;
dispalyIcon += dtchData;
int pos = dispalyIcon.rfind('\\');
dispalyIcon = dispalyIcon.substr(pos + 1, dispalyIcon.length());
if (dispalyIcon == "ZeroTrustSecureClient.exe")
{
// Reopen
if (Judge == 1) {
RegOpenKeyExA(HKEY_LOCAL_MACHINE, strMidReg.c_str(), 0, KEY_WOW64_64KEY | KEY_SET_VALUE, &newKEY);
}
else {
lRet = RegOpenKeyExA(HKEY_CURRENT_USER, data_Set.c_str(), 0, KEY_WOW64_64KEY | KEY_SET_VALUE, &newKEY);
}
BYTE sValue[256] = {
};
memcpy(sValue,value.c_str(),value.size());
RegSetValueEx(newKEY,// Handle to the key to set
key.c_str(),// The name of the key value to access
0,// Reserved values
dwValueType,// The type of data to set
sValue,// The key value to set
dwSize// Length of data
);
}
memset(dtchData, 0, sizeof(char) * dwSize);
}
}
memset(szKeyName, 0, 255);
dwKeyLen = 255;
strMidReg = "";
strBuffer = "";
}
}
RegCloseKey(hKEY);
RegCloseKey(hKEYResult);
RegCloseKey(newKEY);
return true;
}
// Need modification displayName、displayVersion、DisplayIcon、Publisher、UninstallString( Last modified displayIcon)
void SetRegeditValue(std::string key, std::string value)
{
SetRegeditValue("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 1,key,value);
SetRegeditValue("SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 1, key, value);
SetRegeditValue("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, key, value);
}
版权声明
本文为[The old man is outside the door]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230548038861.html
边栏推荐
- vs中的多字节与unicode
- C语言进阶要点笔记2
- C语言中volatile的使用
- Camera calibration: key point method vs direct method
- Round up a little detail of the round
- 文件查看命令和用户管理命令
- Vs can be compiled, but there will be a red underline to indicate the problem of undefined identifiers
- 深蓝学院激光slam理论与实践 -第二章(里程计标定)作业
- Introduction to nonparametric camera distortion model
- 基于TensorFlow的线性回归实例
猜你喜欢
File viewing commands and user management commands
CUDA environment installation
C语言实用小技巧合集(持续更新)
【UDS统一诊断服务】一、诊断概述(2)— 主要诊断协议(K线和CAN)
【UDS统一诊断服务】四、诊断典型服务(4)— 在线编程功能单元(0x34-0x38)
cv_bridge 与opencv 版本不匹配的解决
Running QT program in visual Stdio
[ThreadX] h743 + ThreadX + Filex migration record
Graduation project, curriculum link, student achievement evaluation system
Collection of practical tips for C language (continuously updated)
随机推荐
Vscode custom comments
【UDS统一诊断服务】(补充)五、ECU bootloader开发要点详解 (1)
QT add qserialport class to realize serial port operation
WMI技术介绍和应用
LaTeX配置与使用
Collection of practical tips for C language (continuously updated)
信息学一本通-小球
[learn] HF net training
[UDS unified diagnostic service] II. Network layer protocol (1) - overview and functions of network layer
[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)
_findnext 报错
CUDA project encountered a series of compilation problems after changing the environment (computer)
友元函数,友元类,类模板
文件查看命令和用户管理命令
Shell脚本 单引号、双引号和反引号的区别
【UDS统一诊断服务】五、诊断应用示例:Flash Bootloader
FOC 单电阻采样 位置环控制伺服电机
[opencv] use filestorage to read and write eigenvectors
Understanding of SSH public key and private key
Protection of shared data