#include "..\include_eapi_header.h"#include <optional>#include <algorithm>//替换串中指定文本为空#undef max#undef min//static std::string ReplaceSubText(std::string text, const std::string& to_replace, std::optional<size_t> replace_count = std::nullopt) {// size_t search_start = 0;// size_t count = replace_count.value_or(std::numeric_limits<size_t>::max());// std::string replace = "";// size_t pos = text.find(to_replace, search_start);// while (pos != std::string::npos && count > 0) {// text.replace(pos, to_replace.length(), replace);// pos = text.find(to_replace, pos + replace.length());// --count;// }// return text;//}//static std::vector<std::string> EnumRegistryKey(HKEY root, const std::string& path)//{// DWORD type = 0;// HKEY hKey = 0;// SYSTEM_INFO info;// std::vector<std::string> ret;// GetNativeSystemInfo(&info);// if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (type = KEY_WOW64_32KEY | KEY_ALL_ACCESS, info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {// type = KEY_WOW64_64KEY | KEY_ALL_ACCESS;// }//// if (RegOpenKeyExA(root, path.c_str(), 1, type, &hKey) == ERROR_SUCCESS) {// char name[MAX_PATH] = {};// if (!RegEnumKeyA(hKey, 0, name, MAX_PATH))// {// ret.push_back(name);// DWORD i = 1;// while (!RegEnumKeyA(hKey, i++, name, MAX_PATH))// {// ret.push_back(name);// }// }// RegCloseKey(hKey);// }// return ret;//}////void static DleteMore(const std::string& name, HKEY hkey, const std::string& parentPath, HKEY handle, const std::string& currentPath)////{//// auto subkeys = EnumRegistryKey(hkey, currentPath);//// for (const auto& subkey : subkeys)//// {//// auto fullSubkeyPath = currentPath + "\\" + subkey;//// auto subkeySubkeys = EnumRegistryKey(hkey, fullSubkeyPath);//// if (!subkeySubkeys.empty())//// {//// DleteMore(name, hkey, parentPath, handle, fullSubkeyPath);//// }//// else//// {//// auto keyToDelete = ReplaceSubText(fullSubkeyPath, parentPath + "\\");//// RegDeleteKeyExA(handle, keyToDelete.c_str(), KEY_WOW64_64KEY, 0);//// }//// }//// auto keyToDelete = ReplaceSubText(currentPath, parentPath + "\\");//// RegDeleteKeyExA(handle, keyToDelete.c_str(), KEY_WOW64_64KEY, 0);////}//void static DleteMore(std::string name, HKEY hkey, std::string parpath, HKEY handle, std::string livepath)//{//// std::vector<std::string> data;// DWORD samDesired;// SYSTEM_INFO SystemInfo;// std::string needhandle;// GetNativeSystemInfo(&SystemInfo);// if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 || (samDesired = KEY_WOW64_32KEY, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)) {// samDesired = KEY_WOW64_64KEY;// }// do// {// data = EnumRegistryKey(hkey, livepath);////// for (size_t i = 0; i < data.size(); ++i)// {//// if (!EnumRegistryKey(hkey, livepath + "\\" + data[i]).empty()) {// DleteMore(name, hkey, parpath, handle, livepath + "\\" + data[i]);// }// else {// needhandle = ReplaceSubText(livepath + "\\" + data[i], parpath + "\\", 1);;// RegDeleteKeyExA(handle, needhandle.c_str(), samDesired, 0);//// }// }// } while (EnumRegistryKey(hkey, livepath).size() >= 1);// needhandle = ReplaceSubText(livepath, parpath + "\\");// RegDeleteKeyExA(handle, needhandle.c_str(), samDesired, 0);//}////bool DeleteRightMenu(std::string Rangeorextensiontobeused, std::string Title) {//////// SYSTEM_INFO SystemInfo;//// GetNativeSystemInfo(&SystemInfo);//// REGSAM Accessrights, samDesired;//// if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (Accessrights = KEY_WOW64_32KEY | KEY_ALL_ACCESS, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {//// Accessrights = KEY_WOW64_64KEY | KEY_ALL_ACCESS;//// }//// if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (samDesired = KEY_WOW64_32KEY, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64))//// {//// samDesired = KEY_WOW64_64KEY;//// }//// HKEY hKey;//// ;//// if (RegOpenKeyExA(HKEY_CLASSES_ROOT, 0, 0, Accessrights, &hKey) != ERROR_SUCCESS)//// {//// return false;//// }//////// if (!EnumRegistryKey(HKEY_CLASSES_ROOT, "\\" + Title).empty())//// {//// DleteMore(Title, HKEY_CLASSES_ROOT, "", hKey, "\\" + Title);//// }//// if (RegDeleteKeyExA(hKey, Title.c_str(), samDesired, 0)) {//// RegCloseKey(hKey);//// return false;//// };//// RegCloseKey(hKey);//// return true;////}//bool DeleteRightMenu(const std::string& Rangeorextensiontobeused, const std::string& Title)//{// SYSTEM_INFO SystemInfo;// GetNativeSystemInfo(&SystemInfo);// REGSAM Accessrights = 0, samDesired = 0;//// if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)// {// Accessrights = KEY_WOW64_64KEY | KEY_ALL_ACCESS;// samDesired = KEY_WOW64_64KEY;// }// else if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)// {// Accessrights = KEY_WOW64_32KEY | KEY_ALL_ACCESS;// samDesired = KEY_WOW64_32KEY;// }//// HKEY hKey = 0;// if (RegOpenKeyExA(HKEY_CLASSES_ROOT, 0, 0, Accessrights, &hKey) != ERROR_SUCCESS)// {// return false;// }//// if (!EnumRegistryKey(HKEY_CLASSES_ROOT, "\\" + Title).empty())// {// DleteMore(Title, HKEY_CLASSES_ROOT, "", hKey, "\\" + Title);// }//// if (RegDeleteKeyExA(hKey, Title.c_str(), samDesired, 0))// {// RegCloseKey(hKey);// return false;// }//// RegCloseKey(hKey);// return true;//}// 调用格式: SDT_BOOL 删除右键菜单, 命令说明: "删除指定标题或作用区域右键菜单"// 参数<1>: [作用的区域或扩展名 SDT_TEXT], 参数说明: "右键菜单在什么位置出现,例如指定:.txt,那么右键.txt文件时才会出现添加的菜单," * ":所有地方 ;"D":桌面右键;"URL":文件夹右键;"SAVER":文件右键;".*":指定后缀名右键,按照.*的格式写,不存在则创建(如.txt),默认所有地方生效"// 参数<2>: 右键菜单标题 SDT_TEXT, 参数说明: "右键后显示的标题,同时为类名,删除时指定此参数即可"using namespace std;static std::string ReplaceSubText(std::string text, const std::string& to_replace, std::optional<size_t> replace_count = std::nullopt) {size_t search_start = 0;size_t count = replace_count.value_or(std::numeric_limits<size_t>::max());std::string replace = "";size_t pos = text.find(to_replace, search_start);while (pos != std::string::npos && count > 0) {text.replace(pos, to_replace.length(), replace);pos = text.find(to_replace, pos + replace.length());--count;}return text;}static std::vector<std::string> EnumRegistryKey(HKEY root, const std::string& path){DWORD type = 0;HKEY hKey = 0;SYSTEM_INFO info;std::vector<std::string> ret;GetNativeSystemInfo(&info);if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (type = KEY_WOW64_32KEY | KEY_ALL_ACCESS, info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {type = KEY_WOW64_64KEY | KEY_ALL_ACCESS;}auto A = RegOpenKeyExA(root, path.c_str(), 1, type, &hKey);debug_put((int)root, path, type);if (A == ERROR_SUCCESS) {char name[MAX_PATH] = {};if (!RegEnumKeyA(hKey, 0, name, MAX_PATH)){ret.push_back(name);DWORD i = 1;while (!RegEnumKeyA(hKey, i++, name, MAX_PATH)){ret.push_back(name);}}RegCloseKey(hKey);}return ret;}static void DleteMore(const std::string& name, HKEY hkey, const std::string& parentPath, HKEY handle, const std::string& currentPath){auto subkeys = EnumRegistryKey(hkey, currentPath);for (size_t i = 0; i < subkeys.size(); i++){debug_put(subkeys[i]);}for (const auto& subkey : subkeys){auto fullSubkeyPath = currentPath + "\\" + subkey;auto subkeySubkeys = EnumRegistryKey(hkey, fullSubkeyPath);if (!subkeySubkeys.empty()){DleteMore(name, hkey, parentPath, handle, fullSubkeyPath);}else{auto keyToDelete = ReplaceSubText(fullSubkeyPath, parentPath + "\\");RegDeleteKeyExA(handle, keyToDelete.c_str(), KEY_WOW64_64KEY, 0);}}auto keyToDelete = ReplaceSubText(currentPath, parentPath + "\\");RegDeleteKeyExA(handle, keyToDelete.c_str(), KEY_WOW64_64KEY, 0);}bool static AddRightMenu(string Rangeorextensiontobeused, string Title, string comline, string shortkey, string icon, bool shiftdisplay) {string Actionpath;if (Rangeorextensiontobeused == "*"){Actionpath = "Directory\\Background\\shell";}else if (Rangeorextensiontobeused == "D"){Actionpath = "DesktopBackground\\Shell";}else if (Rangeorextensiontobeused == "URL"){Actionpath = "Directory\\shell";}else{Actionpath = "*\\shell";if (Rangeorextensiontobeused != "SAVER") {Actionpath = Rangeorextensiontobeused;}}HKEY phkResult = 0;SYSTEM_INFO SystemInfo;GetNativeSystemInfo(&SystemInfo);REGSAM Accessrights, samDesired;if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (Accessrights = KEY_WOW64_32KEY | KEY_ALL_ACCESS, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {Accessrights = KEY_WOW64_64KEY | KEY_ALL_ACCESS;}if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (samDesired = KEY_WOW64_32KEY, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)){samDesired = KEY_WOW64_64KEY;}RegCreateKeyExA(HKEY_CLASSES_ROOT, Actionpath.c_str(), 0, 0, 0, Accessrights, 0, &phkResult, 0);if (!phkResult) {return false;}RegSetValueExA(phkResult, "SubCommands", 0, REG_SZ, 0, 0);RegCloseKey(phkResult);string lpSubKey = Actionpath + "\\shell";GetNativeSystemInfo(&SystemInfo);RegCreateKeyExA(HKEY_CLASSES_ROOT, lpSubKey.c_str(), 0, 0, 0, Accessrights, 0, &phkResult, 0);if (!phkResult) {return false;}HKEY hKey = 0;RegOpenKeyExA(HKEY_CLASSES_ROOT, lpSubKey.c_str(), 0, Accessrights, &hKey);string lpPstr = lpSubKey;lpSubKey = lpSubKey + "\\" + Actionpath + "\\shell" + "\\" + Title;if (EnumRegistryKey(HKEY_CLASSES_ROOT, lpSubKey).size() <= 0) {RegDeleteKeyExA(hKey, (Actionpath + "\\shell" + "\\" + Title).c_str(), samDesired, 0);}else{DleteMore((Actionpath + "\\shell" + "\\" + Title), HKEY_CLASSES_ROOT, lpPstr, hKey, lpSubKey);}RegCloseKey(hKey);;RegCloseKey(phkResult);RegCreateKeyExA(HKEY_CLASSES_ROOT, (Actionpath + "\\shell" + "\\" + Title).c_str(), 0, 0, 0, Accessrights, 0, &phkResult, 0);if (!phkResult) {return false;}if (!shortkey.empty()){string temp = Title + "(&" + shortkey + ")";RegSetValueExA(phkResult, "MUIVerb", 0, REG_SZ, (const BYTE*)temp.c_str(), temp.size());}else{RegSetValueExA(phkResult, "MUIVerb", 0, REG_SZ, (const BYTE*)Title.c_str(), Title.size());}if (!icon.empty()){RegSetValueExA(phkResult, "icon", 0, REG_SZ, (const BYTE*)icon.c_str(), icon.size());}if (shiftdisplay) {RegSetValueExA(phkResult, "Extended", 0, REG_SZ, 0, 0);}RegCloseKey(phkResult);RegCreateKeyExA(HKEY_CLASSES_ROOT, (Actionpath + "\\shell" + "\\" + Title + "\\command").c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, Accessrights, NULL, &phkResult, NULL);if (phkResult){RegSetValueExA(phkResult, 0, 0, REG_SZ, (const BYTE*)comline.c_str(), comline.size());return 1;}return 0;}bool static DeleteRightMenu(string Rangeorextensiontobeused, string Title) {SYSTEM_INFO SystemInfo;GetNativeSystemInfo(&SystemInfo);REGSAM Accessrights, samDesired;if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (Accessrights = KEY_WOW64_32KEY | KEY_ALL_ACCESS, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)) {Accessrights = KEY_WOW64_64KEY | KEY_ALL_ACCESS;}if (SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || (samDesired = KEY_WOW64_32KEY, SystemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)){samDesired = KEY_WOW64_64KEY;}HKEY hKey;;if (RegOpenKeyExA(HKEY_CLASSES_ROOT, 0, 0, Accessrights, &hKey) != ERROR_SUCCESS){return false;}if (!EnumRegistryKey(HKEY_CLASSES_ROOT, "\\" + Title).empty()){DleteMore(Title, HKEY_CLASSES_ROOT, "", hKey, "\\" + Title);}if (RegDeleteKeyExA(hKey, Title.c_str(), samDesired, 0)) {RegCloseKey(hKey);return false;};RegCloseKey(hKey);return true;}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。