我想在运行我的代码之后启动计算机中的.exe程序,并且在程序打开后仍然执行一些操作,但是我一直在如何打开它。如何在c中执行外部程序
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//#define _WIN32_WINNT 0x0500
#include <windows.h>
int main() {
POINT mouse;
//HWND hWnd = GetConsoleWindow();
//ShowWindow(hWnd, SW_MINIMIZE);
//ShowWindow(hWnd, SW_HIDE);
// how to open program ?
system("start C:\Riot Games\League of Legends\LeagueClient.exe");
while (true) {
GetCursorPos(&mouse);
int x = mouse.x;
int y = mouse.y;
SetCursorPos(x + rand() % 40 - 20, y + rand() % 40 - 20);
printf("x = %d ", mouse.x);
printf("y = %d\n", mouse.y);
Sleep(1);
}
}
由于两个原因,系统函数不适用于我;它暂停代码,直到应用程序退出,并且当我尝试运行代码时,它说他找不到C:Riot。
'system()'函数等待执行的命令完成。在Linux或Mac上,您可以“fork()”或运行在后台启动外部可执行文件的命令。但是Windows没有'fork()',我也不确定它是否具有后台进程。您将需要Windows API的适当功能。 –
哦,我明白了,谢谢。我会尽力找到它。 –