running external program

 

Does anybody know if there's a way I can code my ea such that when all positions close, it will run "c:\shutdown.exe" which turns off my pc?


is there a run command or shell command anyone is familiar with? Thanks! :)

 
heyarn:

Does anybody know if there's a way I can code my ea such that when all positions close, it will run "c:\shutdown.exe" which turns off my pc?


is there a run command or shell command anyone is familiar with? Thanks! :)

You have to import shell32.dll to run external programs:


#import "shell32.dll"

int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);

#import


Then when you want to run it you do it this way:

ShellExecuteA(0, "Open", "c:\shutdown.exe", "", "", 1);



 
robofx.org:

You have to import shell32.dll to run external programs:


#import "shell32.dll"

int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);

#import


Then when you want to run it you do it this way:

ShellExecuteA(0, "Open", "c:\shutdown.exe", "", "", 1);



thanks robofx!

 
robofx.org:

You have to import shell32.dll to run external programs:


#import "shell32.dll"

int ShellExecuteA(int hwnd,string Operation,string File,string Parameters,string Directory,int ShowCmd);

#import


Then when you want to run it you do it this way:

ShellExecuteA(0, "Open", "c:\shutdown.exe", "", "", 1);



do we need to copy shell32 dll form windows folder to experts/libraries or just use this code snippet only ?
 
lakshij:
do we need to copy shell32 dll form windows folder to experts/libraries or just use this code snippet only ?

just use the code
 
does not wrk for me :( . i did the code as robofx.org says. it did nothing but shows cmd n within a moment it dissapear just like that n pc doesnt get shutdwn.can anyone help me ?
 
lakshij:
does not wrk for me :( . i did the code as robofx.org says. it did nothing but shows cmd n within a moment it dissapear just like that n pc doesnt get shutdwn.can anyone help me ?

The example above would work if shutdown.exe file exists in C:\

Here's the universal way:

ShellExecuteA(0, "Open", "C:\Windows\System32\shutdown.exe", "/s /t 120", "", 1);

This will shutdown PC in 120 seconds.

Or:

ShellExecuteA(0, "Open", "C:\Windows\System32\shutdown.exe", "/s /t 0", "", 1);

to shutdown immediately.

Make sure you have enabled DLL files in MT4.

 
robofx.org:

The example above would work if shutdown.exe file exists in C:\

Here's the universal way:

ShellExecuteA(0, "Open", "C:\Windows\System32\shutdown.exe", "/s /t 120", "", 1);

This will shutdown PC in 120 seconds.

Or:

ShellExecuteA(0, "Open", "C:\Windows\System32\shutdown.exe", "/s /t 0", "", 1);

to shutdown immediately.

Make sure you have enabled DLL files in MT4.


or don't use path at all just

ShellExecuteA(0, "Open", "shutdown.exe", "/s /t 0", "", 1);

 
robofx.org:

The example above would work if shutdown.exe file exists in C:\

Here's the universal way:

ShellExecuteA(0, "Open", "C:\Windows\System32\shutdown.exe", "/s /t 120", "", 1);

This will shutdown PC in 120 seconds.

Or:

ShellExecuteA(0, "Open", "C:\Windows\System32\shutdown.exe", "/s /t 0", "", 1);

to shutdown immediately.

Make sure you have enabled DLL files in MT4.

thanx nw its wrking
Reason: