taskkill /im GATESRV.exe /f & taskkill /im MasterHelper.exe /f & sc stop TdNetFilter

sc stop TDFileFilter 

sc delete TDFileFilter



//开网2.0
#include <iostream>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501  
#endif
LONG WINAPI MyRegDeleteTree(HKEY hKey, LPCTSTR lpSubKey) {
    HKEY hSubKey;
    LONG lResult;
    TCHAR szKeyName[256];
    DWORD dwIndex = 0;
    lResult = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_READ | KEY_WRITE, &hSubKey);
    if (lResult != ERROR_SUCCESS) {
        return lResult;
    }
    while (RegEnumKey(hSubKey, dwIndex, szKeyName, 256) == ERROR_SUCCESS) {
        MyRegDeleteTree(hSubKey, szKeyName);
        dwIndex++;
    }
    RegCloseKey(hSubKey);
    return RegDeleteKey(hKey, lpSubKey);
}
bool IsProcessRunning(const TCHAR* processName);
bool IsServiceRunning(const TCHAR* serviceName);
bool StopService(const TCHAR* serviceName);
bool KillProcessByName(const TCHAR* processName);
bool DisableFirewallRulesViaCMD();
bool ResetGroupPolicy();
bool ClearWFPFilters();
bool UnblockApplicationNetwork();
void EnablePrivilege();
int main() {
    MessageBox(NULL,"请等到显示恢复成功再关闭程序","开网2.0",MB_OK);
    EnablePrivilege();
    std::cout << "========================================" << std::endl;
    std::cout << "    高级网络限制解除工具 v2.0" << std::endl;
    std::cout << "========================================" << std::endl;
    std::cout << "正在尝试恢复网络..." << std::endl;
    std::cout << std::endl;
    const TCHAR* serviceName = TEXT("tdnetfilter");
    if (IsServiceRunning(serviceName)) {
        std::cout << "[1/7] 检测到网络过滤服务 (" << serviceName << "),正在尝试停止..." << std::endl;
        if (StopService(serviceName)) {
            std::cout << "     ? 服务停止成功。" << std::endl;
        } else {
            std::cout << "     ? 服务停止失败,请确保以管理员身份运行。" << std::endl;
        }
    } else {
        std::cout << "[1/7] 网络过滤服务未运行,跳过。" << std::endl;
    }
    std::cout << "[2/7] 检查并结束极域相关进程..." << std::endl;
    const TCHAR* helperProcesses[] = {TEXT("MasterHelper.exe"), TEXT("StudentMain.exe"), TEXT("Student.exe"), TEXT("ClassCtrl.exe")};
    for (int i = 0; i < 4; i++) {
        const TCHAR* processName = helperProcesses[i];
        if (IsProcessRunning(processName)) {
            std::cout << "     检测到进程 " << processName << ",正在尝试结束..." << std::endl;
            if (KillProcessByName(processName)) {
                std::cout << "         ? 进程结束成功。" << std::endl;
            } else {
                std::cout << "         ? 进程结束失败。" << std::endl;
            }
        }
    }
    std::cout << "[3/7] 检查并禁用阻止程序的防火墙规则..." << std::endl;
    if (DisableFirewallRulesViaCMD()) {
        std::cout << "     ? 已禁用阻止性防火墙规则。" << std::endl;
    } else {
        std::cout << "     ? 未找到或无法禁用相关防火墙规则。" << std::endl;
    }
    std::cout << "[4/7] 重置应用程序网络策略..." << std::endl;
    if (ResetGroupPolicy()) {
        std::cout << "     ? 组策略重置成功。" << std::endl;
    } else {
        std::cout << "     ? 组策略重置可能不完整。" << std::endl;
    }
    std::cout << "[5/7] 清除WFP网络过滤层..." << std::endl;
    if (ClearWFPFilters()) {
        std::cout << "     ? WFP过滤器已清除。" << std::endl;
    } else {
        std::cout << "     ? WFP清除失败。" << std::endl;
    }
    std::cout << "[6/7] 解除应用程序网络锁定..." << std::endl;
    if (UnblockApplicationNetwork()) {
        std::cout << "     ? 应用程序网络限制已解除。" << std::endl;
    } else {
        std::cout << "     ? 部分应用程序可能仍需手动解除限制。" << std::endl;
    }
    std::cout << "[7/7] 刷新网络设置..." << std::endl;
    system("ipconfig /flushdns > nul 2>&1");
    system("netsh wininet reset proxy > nul 2>&1");
    std::cout << "     ? 网络设置已刷新。" << std::endl;
    std::cout << std::endl;
    std::cout << "========================================" << std::endl;
    std::cout << "操作执行完毕!" << std::endl;
    std::cout << "请尝试运行之前被限制的应用程序。" << std::endl;
    std::cout << "========================================" << std::endl;
    MessageBox(NULL,"恢复网络成功","开网2.0",MB_OK);
    system("pause");
    return 0;
}
void EnablePrivilege() {
    HANDLE hToken;
    TOKEN_PRIVILEGES tp;
    LUID luid;
    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) {
        return;
    }
    if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) {
        tp.PrivilegeCount = 1;
        tp.Privileges[0].Luid = luid;
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
        AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);
    }
    CloseHandle(hToken);
}
bool DisableFirewallRulesViaCMD() {
    FILE* bat = fopen("temp_firewall.bat", "w");
    if (!bat) return false;
    fprintf(bat, "@echo off\n");
    fprintf(bat, "netsh advfirewall set allprofiles state off > nul 2>&1\n");
    fprintf(bat, "netsh firewall set opmode mode=disable > nul 2>&1\n");
    fprintf(bat, "del temp_firewall.bat\n");
    fclose(bat);
    system("temp_firewall.bat > nul 2>&1");
    return true;
}
bool ResetGroupPolicy() {
    HKEY hKey;
    bool result = false;
    if (RegOpenKeyEx(HKEY_CURRENT_USER, 
        TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Group Policy Objects"), 
        0, KEY_SET_VALUE | KEY_WRITE, &hKey) == ERROR_SUCCESS) {
        MyRegDeleteTree(hKey, TEXT(""));
        RegCloseKey(hKey);
        result = true;
    }
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
        TEXT("Software\\Policies\\Microsoft\\Windows\\Safer"),
        0, KEY_SET_VALUE | KEY_WRITE, &hKey) == ERROR_SUCCESS) {
        MyRegDeleteTree(hKey, TEXT(""));
        RegCloseKey(hKey);
        result = true;
    }
    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
        TEXT("Software\\Policies\\Microsoft\\Windows\\SrpV2"),
        0, KEY_SET_VALUE | KEY_WRITE, &hKey) == ERROR_SUCCESS) {
        MyRegDeleteTree(hKey, TEXT(""));
        RegCloseKey(hKey);
        result = true;
    }
    system("gpupdate /force > nul 2>&1");
    return result;
}
bool ClearWFPFilters() {
    SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (!hSCManager) return false;
    bool result = false;
    SC_HANDLE hService = OpenService(hSCManager, TEXT("BFE"), SERVICE_STOP | SERVICE_START | SERVICE_QUERY_STATUS);
    if (hService) {
        SERVICE_STATUS status;
        if (QueryServiceStatus(hService, &status) && status.dwCurrentState == SERVICE_RUNNING) {
            if (ControlService(hService, SERVICE_CONTROL_STOP, &status)) {
                Sleep(2000);
            }
            StartService(hService, 0, NULL);
            result = true;
        }
        CloseServiceHandle(hService);
    }
    hService = OpenService(hSCManager, TEXT("MpsSvc"), SERVICE_STOP | SERVICE_START);
    if (hService) {
        SERVICE_STATUS status;
        ControlService(hService, SERVICE_CONTROL_STOP, &status);
        Sleep(1000);
        StartService(hService, 0, NULL);
        result = true;
        CloseServiceHandle(hService);
    }
    CloseServiceHandle(hSCManager);
    system("netsh advfirewall reset > nul 2>&1");
    return result;
}
bool UnblockApplicationNetwork() {
    HKEY hKey;
    if (RegOpenKeyEx(HKEY_CURRENT_USER,
        TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"),
        0, KEY_SET_VALUE, &hKey) == ERROR_SUCCESS) {
        DWORD autoDetect = 1;
        RegSetValueEx(hKey, TEXT("AutoDetect"), 0, REG_DWORD, (BYTE*)&autoDetect, sizeof(autoDetect));
        DWORD proxyEnable = 0;
        RegSetValueEx(hKey, TEXT("ProxyEnable"), 0, REG_DWORD, (BYTE*)&proxyEnable, sizeof(proxyEnable));
        RegCloseKey(hKey);
    }
    return true;
}
bool IsProcessRunning(const TCHAR* processName) {
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot == INVALID_HANDLE_VALUE) return false;
    PROCESSENTRY32 pe;
    pe.dwSize = sizeof(PROCESSENTRY32);
    if (Process32First(hSnapshot, &pe)) {
        do {
            if (_tcsicmp(pe.szExeFile, processName) == 0) {
                CloseHandle(hSnapshot);
                return true;
            }
        } while (Process32Next(hSnapshot, &pe));
    }
    CloseHandle(hSnapshot);
    return false;
}
bool IsServiceRunning(const TCHAR* serviceName) {
    SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
    if (!hSCManager) return false;
    SC_HANDLE hService = OpenService(hSCManager, serviceName, SERVICE_QUERY_STATUS);
    if (!hService) {
        CloseServiceHandle(hSCManager);
        return false;
    }
    SERVICE_STATUS status;
    bool isRunning = false;
    if (QueryServiceStatus(hService, &status)) {
        isRunning = (status.dwCurrentState == SERVICE_RUNNING);
    }
    CloseServiceHandle(hService);
    CloseServiceHandle(hSCManager);
    return isRunning;
}
bool StopService(const TCHAR* serviceName) {
    SC_HANDLE hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
    if (!hSCManager) return false;
    SC_HANDLE hService = OpenService(hSCManager, serviceName, SERVICE_STOP | SERVICE_QUERY_STATUS);
    if (!hService) {
        CloseServiceHandle(hSCManager);
        return false;
    }
    SERVICE_STATUS status;
    bool result = ControlService(hService, SERVICE_CONTROL_STOP, &status);
    CloseServiceHandle(hService);
    CloseServiceHandle(hSCManager);
    return result;
}
bool KillProcessByName(const TCHAR* processName) {
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot == INVALID_HANDLE_VALUE) return false;
    PROCESSENTRY32 pe;
    pe.dwSize = sizeof(PROCESSENTRY32);
    bool killedAny = false;
    if (Process32First(hSnapshot, &pe)) {
        do {
            if (_tcsicmp(pe.szExeFile, processName) == 0) {
                HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID);
                if (hProcess) {
                    if (TerminateProcess(hProcess, 0)) {
                        killedAny = true;
                    }
                    CloseHandle(hProcess);
                }
            }
        } while (Process32Next(hSnapshot, &pe));
    }
    CloseHandle(hSnapshot);
    return killedAny;
}