我想在運行我的代碼之後啓動計算機中的.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的適當功能。 –
哦,我明白了,謝謝。我會盡力找到它。 –