挂起极域电子教室客户端

Code

#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>

// ==============================

void printLogHead();
void minimizeForegroundWindow();
int getPid(char*);

// ==============================

int main()
{
    typedef long (NTAPI *_NtSuspendProcess)(IN HANDLE handle);
    _NtSuspendProcess NtSuspendProcess = (_NtSuspendProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtSuspendProcess");
    typedef long (NTAPI *_NtResumeProcess)(IN HANDLE handle);
    _NtResumeProcess NtResumeProcess = (_NtResumeProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtResumeProcess");
    typedef long (NTAPI *_NtTerminateProcess)(IN HANDLE handle);
    _NtTerminateProcess NtTerminateProcess = (_NtTerminateProcess)GetProcAddress(GetModuleHandle("ntdll"), "NtTerminateProcess");

    int pid = getPid((char*)"notepad.exe"); // StudentMain.exe
    if (pid)
    {
        printLogHead();
        printf("Suspend: Win + Alt + S\n");
        printLogHead();
        printf("Resume: Win + Alt + R\n");
        printLogHead();
        printf("Kill: Win + Alt + K\n");
    }
    else
    {
        printLogHead();
        printf("Process not found\n");
        printLogHead();
        printf("Press any key to exit\n");
        getchar();
        return 1;
    }
    HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
    // MOD_ALT | MOD_CONTROL | MOD_SHIFT | MOD_WIN
    RegisterHotKey(NULL, 1, MOD_WIN | MOD_ALT, 'S'); // Suspend
    RegisterHotKey(NULL, 2, MOD_WIN | MOD_ALT, 'R'); // Resume
    RegisterHotKey(NULL, 3, MOD_WIN | MOD_ALT, 'K'); // Kill
    MSG msg = {0};
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (msg.message == WM_HOTKEY)
        {
            switch (msg.wParam)
            {
                case 1:
                    NtSuspendProcess(handle);
                    Sleep(350); // Wait until the key pops up and the desktop is loaded
                    minimizeForegroundWindow();
                    NtResumeProcess(handle); // Temporarily recover the process
                    Sleep(100);
                    NtSuspendProcess(handle);
                    printLogHead();
                    printf("Process %d has been suspended\n", pid);
                    break;
                case 2:
                    for(int i = 0; i < 9; i++)
                    {
                        NtResumeProcess(handle);
                    }
                    printLogHead();
                    printf("Process %d has been resumed\n", pid);
                    break;
                case 3:
                    NtTerminateProcess(handle);
                    printLogHead();
                    printf("Process %d has been killed\n", pid);
                    printLogHead();
                    printf("Press any key to exit\n");
                    getchar();
                    return 0;
                    break;
            }
        }
    }
    getchar();
    return 0;
}

void printLogHead()
{
    SYSTEMTIME time; 
    GetLocalTime(&time);
    printf("[%02d:%02d:%02d] ", time.wHour, time.wMinute, time.wSecond);
    return;
}

void minimizeForegroundWindow()
{
    HWND hwnd = GetForegroundWindow();
    ShowWindow(hwnd, SW_MINIMIZE);
    return;
}

int getPid(char* processName)
{
    HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    PROCESSENTRY32 pe32;
    pe32.dwSize = sizeof(PROCESSENTRY32);
    int pid = 0;
    do
    {
        if (!lstrcmpi(processName, pe32.szExeFile))
        {
            pid = pe32.th32ProcessID;
            break;
        }
    }
    while (Process32Next(handle, &pe32));
    CloseHandle(handle);
    return pid;
}

Introduction

https://pan.baidu.com/s/1CrVYB_ysCSCUwATTCe8zTQ

Password:if7f

Update History

20190404

20181109

20180907