RUN statement

Purpose: Asynchronously start and run another program or system file


 Syntax:

 RUN Name$ [, ShowWindowState, WaitState]

 Parameters:

  • Name$ Program to run or file to be loaded.
  • ShowWindowState [OPTIONAL] Sets the state of the window in which the called program will be run. The following are Win32 API CONSTANTS defined in the C compiler's WinUser.h header file and can be used in the ShowWindowState parameter.
    
     'Constant         Value 
     
     SW_HIDE             0
     SW_SHOWNORMAL       1
     SW_NORMAL           1
     SW_SHOWMINIMIZED    2
     SW_SHOWMAXIMIZED    3
     SW_MAXIMIZE         3
     SW_SHOWNOACTIVATE   4
     SW_SHOW             5
     SW_MINIMIZE         6
     SW_SHOWMINNOACTIVE  7
     SW_SHOWNA           8
     SW_RESTORE          9
     SW_SHOWDEFAULT     10
     SW_FORCEMINIMIZE   11
     SW_MAX             11
    
    
    Default value of ShowWindowState is 1 which is SW_SHOWNORMAL.
  • WaitState [OPTIONAL] Set WaitState to 1 to cause the calling application to wait for the called application to exit before continuing execution. The default value is 0 which will cause the calling function not to wait for the called function to complete before continuing execution.

Examples :


 RUN "notepad.exe", SW_SHOW ' Start up Notepad

 RUN "start http://www.w3.org", SW_HIDE ' Launches default browser 

In the example above, SW_HIDE is used to hide the DOS box that 'start' initiates. If you are using 'start' to execute a console application in a Windows DOS box and you want to see the screen output then set the parameter to one of the SW_SHOW parameters.

Remarks: The above example using 'start' will not work on Windows 2000 or XP because 'start' does not function in the same way on Windows 2000, XP as it does on Windows 95 and 98. There are two alternatives for 2000, XP users

1. Use Windows API:


 ShellExecute(0, _       ' handle to parent window
 "open", _               ' pointer to string that specifies operation to perform
 "http://www.w3.org", _  ' pointer to filename string
 "", _                   ' pointer to string that specifies executable-file parameters
 0, _                    ' pointer to string that specifies default folder
 1 _                     ' whether file is shown when opened
)

Remarks: To use the ShellExecute WinAPI call you must link with SHELL32.LIB.

2. Use a macro :

 CONST RunEx(lpFile, _
       lpParameters, _
         nShowCmd) = _
     ShellExecute(0, _
             "open", _
             lpFile, _
       lpParameters, _
                  0, _
           nShowCmd)

Remarks: To use this macro you must link with SHELL32.LIB. The following shows how RunEx would be called in the application.


 RunEx("notepad.exe", "xxx.txt", 1)