当前位置:网站首页>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
边栏推荐
猜你喜欢

C语言实用小技巧合集(持续更新)

【UDS统一诊断服务】四、诊断典型服务(1)— 诊断和通信管理功能单元

PHP junior programmers, take orders and earn extra money

拷贝构造函数

Opencv uses genericindex for KNN search
![[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)](/img/98/becd691d3d46f74f7666f5cb323eaf.png)
[UDS unified diagnostic service] IV. typical diagnostic service (5) - function / component test function unit (routine function unit 0x31)

cv_bridge 与opencv 版本不匹配的解决

For() loop parameter call order

MOS管特性和导通过程

【UDS统一诊断服务】二、网络层协议(1)— 网络层概述与功能
随机推荐
C语言的运算符
进程管理命令
【踩坑】Win11 WSL2 中 meld 无法正常使用问题修复
Wechat applet request encapsulation
ARM常用汇编指令
C语言实用小技巧合集(持续更新)
基于VGG卷积神经网络的图像识别代码实现
友元函数,友元类,类模板
修改注册表的值
Tabbar implementation of dynamic bottom navigation bar in uniapp, authority management
汇编基础代码示例
[UDS unified diagnosis service] i. diagnosis overview (1) - diagnosis overview
Generate shortcut
VHDL-任意分频器(50%占空比)
Understanding of SSH public key and private key
CUDA project encountered a series of compilation problems after changing the environment (computer)
声明为全局变量
_findnext 报错
圆整 round 的一点点小细节
HDU-Memory Control