当前位置:网站首页>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
边栏推荐
猜你喜欢
[UDS unified diagnosis service] IV. typical diagnosis service (3) - read fault information function unit (storage data transmission function unit)
Class inheritance and derivation
[UDS unified diagnosis service] i. diagnosis overview (1) - diagnosis overview
[ThreadX] h743zi + lan8720 + ThreadX + netx duo transplantation
[ThreadX] ThreadX source code reading plan (I)
C语言的运算符
逻辑回归原理及代码实现
PHP junior programmers, take orders and earn extra money
Graduation project, curriculum link, student achievement evaluation system
【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元
随机推荐
CUDA environment installation
OpenCV使用 GenericIndex 进行 KNN 搜索
Vs can be compiled, but there will be a red underline to indicate the problem of undefined identifiers
Friend function, friend class, class template
[stepping on the pit] MELD in win11 wsl2 cannot be used normally. Problem repair
Installation of GCC, G + +, GDB
C语言实用小技巧合集(持续更新)
Qt 添加QSerialPort类 实现串口操作
C [document operation] PDF files and pictures are converted to each other
Notes on advanced points of C language 5
HDU-Tunnel Warfare
C语言 #和##的使用
Initialization of classes and objects (constructors and destructors)
PM2 deploy nuxt related commands
逻辑回归原理及代码实现
C语言进阶要点笔记4
The waterfall waterfall flow of uview realizes single column and loads more
Eigen 学习总结
Introduction to nonparametric camera distortion model
Static member