脱离控制,按0脱空,按1连接MAX版
2025-09-21 20:11:54
发布于:江苏
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
using namespace std;
bool IsAdmin() {
BOOL isAdmin = FALSE;
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
if (AllocateAndInitializeSid(&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup)) {
if (!CheckTokenMembership(NULL, AdministratorsGroup, &isAdmin)) {
isAdmin = FALSE;
}
FreeSid(AdministratorsGroup);
}
return isAdmin;
}
bool ControlServiceState(bool enable) {
SC_HANDLE scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!scm) return false;
SC_HANDLE service = OpenService(scm, "TClassSrv", SERVICE_ALL_ACCESS);
if (!service) {
CloseServiceHandle(scm);
return false;
}
SERVICE_STATUS status;
bool result = false;
if (enable) {
result = StartService(service, 0, NULL);
} else {
result = ControlService(service, SERVICE_CONTROL_STOP, &status);
}
CloseServiceHandle(service);
CloseServiceHandle(scm);
return result;
}
void ShowMenu() {
system("cls");
cout << "=== 极域电子教室控制面板 ===" << endl;
cout << "当前状态: " << (ControlServiceState(true) ? "已连接" : "已断开") << endl;
cout << "--------------------------" << endl;
cout << "按 0 临时脱控(保留文件传输)" << endl;
cout << "按 1 重新连接教师端" << endl;
cout << "按 ESC 退出程序" << endl;
cout << "--------------------------" << endl;
}
int main() {
if (!IsAdmin()) {
MessageBox(NULL, "请以管理员身份运行本程序!", "权限错误", MB_ICONERROR);
return 1;
}
while (true) {
ShowMenu();
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) break;
if (GetAsyncKeyState('0') & 0x8000) {
if (ControlServiceState(false)) {
cout << "\a操作成功:已临时脱控" << endl;
} else {
cout << "\a操作失败:请检查服务状态" << endl;
}
Sleep(1000);
}
else if (GetAsyncKeyState('1') & 0x8000) {
if (ControlServiceState(true)) {
cout << "\a操作成功:已恢复连接" << endl;
} else {
cout << "\a操作失败:请检查服务状态" << endl;
}
Sleep(1000);
}
Sleep(100);
}
return 0;
}
这里空空如也
有帮助,赞一个