赞
踩
- #include <cstdlib> // 包含 std::system
- #include <iostream> // 包含 std::system
- #include <windows.h>
- #include <fstream>
- #include <string>
- #include <thread>
- #include <chrono>
-
- bool AddToStartup(const char* exePath) {
- HKEY hKey;
- const char* subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
- const char* valueName = "close_Windows_Defender"; // 你可以更改这个名称
-
- // 尝试打开或创建注册表项
- if (RegCreateKeyExA(HKEY_LOCAL_MACHINE, subKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) != ERROR_SUCCESS) {
- std::cerr << "无法创建或打开注册表项: " << subKey << std::endl;
- return false;
- }
-
- // 尝试设置注册表值
- if (RegSetValueExA(hKey, valueName, 0, REG_SZ, (LPBYTE)exePath, (DWORD)strlen(exePath) + 1) != ERROR_SUCCESS) {
- std::cerr << "无法设置注册表值: " << valueName << std::endl;
- RegCloseKey(hKey);
- return false;
- }
-
- // 关闭注册表项句柄
- RegCloseKey(hKey);
-
- std::cout << "程序已成功添加到开机启动项中。" << std::endl;
- return true;
- }
-
- int main()
- {
- std::this_thread::sleep_for(std::chrono::seconds(2));//2秒钟后启动
-
- const char* exePath = "D:\\close_Windows_Defender.exe"; // 替换为你的程序路径
-
- // 检查是否成功添加到开机启动项
- if (AddToStartup(exePath))
- {
- //std::cout << "程序将在下次系统启动时自动运行。" << std::endl;
- }
-
-
-
- // PowerShell 脚本命令,禁用实时保护
- const char* command = "powershell.exe -ExecutionPolicy Bypass -Command \"Set-MpPreference -DisableRealtimeMonitoring $true\"";
-
- // 调用 PowerShell 脚本
- int result = std::system(command);
-
- // 检查返回值
- if (result == 0)
- {
- //std::cout << "PowerShell script executed successfully." << std::endl;
- }
- else
- {
- //std::cerr << "Error executing PowerShell script." << std::endl;
- }
-
- // 创建一个ofstream对象,并打开一个文件以写入
- std::ofstream outfile;
- outfile.open("D:\\close_Windows_Defender_RiZhi.txt");
-
- // 检查文件是否成功打开
- if (outfile.is_open())
- {
- // 写入字符串到文件
- std::string str = "success!";
- outfile << str << std::endl;
-
- // 关闭文件
- outfile.close();
- }
-
-
-
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。