failed to close another MT5 instances

 

Hi, I want to close another MT5 instances. To do that I use WinExec function. This is how I do it,

int end=WinExec("taskkill D:\Metatrader5 - Tester\terminal64.exe", 0);

It returns error 2. Is this a correct way to use WinExec?

 

Instead using WinExec function, I suggest you use ShellExeceuteW. To do that you need to create this bat file and call it using ShellExecuteW

//bat file

For /F "skip=1" %%a in ('wmic process where "ExecutablePath='D:\\Eightcap - MT5\\terminal64.exe'" get ProcessID') do taskkill /f /pid %%a

//call it using ShellExecuteW

int ret = ShellExecuteW(0, "open", "D:\\Taskkill.bat", "", "", 0);
if(ret < 32)

   Print("Error code ", ret);