脱离控制,按0脱空,按1连接
2025-09-21 19:52:35
发布于:江苏
#include <windows.h>
#include <tlhelp32.h>
#include <iostream>
using namespace std;
// 检查管理员权限
bool IsAdmin() {
SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY;
PSID AdministratorsGroup;
BOOL isAdmin = AllocateAndInitializeSid(
&NtAuthority, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &AdministratorsGroup);
if (isAdmin) {
CheckTokenMembership(NULL, AdministratorsGroup, &isAdmin);
FreeSid(AdministratorsGroup);
}
return isAdmin;
}
// 控制极域服务状态
bool ControlClassService(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 ShowControlPanel() {
system("cls");
cout << "=== 极域电子教室控制面板 ===" << endl;
cout << "当前状态: " << (ControlClassService(true) ? "已连接" : "已断开") << endl;
cout << "--------------------------" << endl;
cout << "按 0 临时脱控(仍可收文件)" << endl;
cout << "按 1 重新连接教师端" << endl;
cout << "按 ESC 退出程序" << endl;
cout << "--------------------------" << endl;
}
int main() {
if (!IsAdmin()) {
cout << "错误:请以管理员身份运行本程序!" << endl;
system("pause");
return 1;
}
while (true) {
ShowControlPanel();
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) break;
if (GetAsyncKeyState('0') & 0x8000) {
ControlClassService(false);
cout << "\a操作成功:已临时脱控" << endl;
Sleep(1000);
}
else if (GetAsyncKeyState('1') & 0x8000) {
ControlClassService(true);
cout << "\a操作成功:已恢复连接" << endl;
Sleep(1000);
}
Sleep(100);
}
return 0;
}
这里空空如也
有帮助,赞一个