CreateProcessEx

Runs an external process using the CreateProcess API including the ability to redirect output to a file and Wait for completion.

CreateProcessEx has a number of advantages over using the RUN command including a much longer command line limit and the ability to understand long filenames correctly.

CreateProcessEx provides the ability to pipe output into an output file - a feature that is not available for the CreateProcess function.

This function is a standalone function and not a member of the wwAPI class.

This function requires WWIPSTUFF.DLL.

CreateProcessEx(lcExe,lcCommandLine,lcStartDirectory,;
              lnShowWindow,llWaitForCompletion,lcStdOutputFilename)

Return Value

.t. or .f.

Parameters

lcExe
Full path to the EXE file. You need a full path even if the file lives in the SYSTEM directory.

lcCommandLine
Optional - Command line arguments for the application.

lcStartDirectory
Optional - The directory that the application runs out of. Don't pass to use the current directory.

lnShowWindow
Optional - The display mode/sizing of how the window is displayed. Uses a numeric value that comes from standard Windows API values:

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

llWaitForCompletion
If .T. waits for the process to complete before control returns back to FoxPro. This is a common requirement for execution so you can capture output and determine success of an operation. Note: internally handled via WaitHandles to get around CreateProcess' asynchronous nature.

lcStdOutputFileName
Allows you to specify a file that captures the Standard Output results. Great for capturing output from Console applications directly to a file.

Example

FUNCTION SetACL(lcPath,lcUser,lcAccess,llInherit,llReplace)
LOCAL lcCommand, lcFile, lcParms

*** Strip off any trailing backslashes
IF RIGHT(lcPath,1)="\" AND LEN(lcPath) > 1
   lcPath = SUBSTR(lcPath,1,LEN(lcPath)-1)
ENDIF

lcParms = ShortPath( lcPath) 
IF llInherit
   lcParms = lcParms + " /T "
ENDIF
IF !llReplace 
   lcParms = lcParms + " /E " 
ENDIF
lcParms = lcParms + " /P " + lcUser + ":" + lcAccess


*** Use CreateProcessEx if wwIPStuff is available
*** so we don't get flashing DOS Windows
LOCAL oAPI
oAPI = CREATEOBJECT("wwAPI")
CreateProcessEx( oAPI.GetSystemDir() + "cacls.exe",ALLTRIM(lcParms),,0,.t.,;
                 FULLPATH("cacls.txt"))

See also:

Class wwAPI

© West Wind Technologies, 2004-2017 • Updated: 10/26/10
Comment or report problem with topic