回复 10楼 nbaqqqq
Sleep 函数是延迟XX秒。#include <Windows.h> #include <TlHelp32.h> #include <stdio.h> int main(int argc, char* argv[]) { if (2 != argc) { printf("参数错误.\n"); return -1; } PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (INVALID_HANDLE_VALUE == hProcessSnap) { printf("CreateToolhelp32Snapshot调用失败.\n"); return -1; } bool IsExist = Process32First(hProcessSnap, &pe32); while (IsExist) { if (0 == strcmp(argv[1], pe32.szExeFile)) { TerminateProcess(OpenProcess(PROCESS_ALL_ACCESS, false, pe32.th32ProcessID),0); printf("进程 %s 已被关闭.\n", argv[1]); CloseHandle(hProcessSnap); return 0; } IsExist = Process32Next(hProcessSnap,&pe32); } printf("没有找到进程 %s.\n", argv[1]); CloseHandle(hProcessSnap); return 0; }