Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Run an EXE and wait for it to finish
Message
 
 
To
25/08/2004 12:05:49
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00936327
Message ID:
00936577
Views:
25
Hi Marcia

Thanks for the reply.

Hope you and Andy are keeping OK.

John


>I need to run an exe from our application and wait for it to finish, then continuing running our application. I have tried using the RUN command but it doesn’t wait for the other exe to finish. This needs to work with all versions of Windows from 95 to XP.
>
>
>LPARAMETERS tcFileName
>#DEFINE INFINITE  0xFFFFFFFF
>
>LOCAL ARRAY laJunk[1]
>LOCAL lnRes, lcStartupInfo, lcProcInfo, lnHandle
>
>*** Load DLLs if necessary
>lnRes = ADLLS( laJunk )
>IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'GetLastError', 1, -1, 1, 15 ) > 0)
>  *** We don't have the function available
>  DECLARE INTEGER GetLastError IN kernel32
>ENDIF
>IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'CloseHandle', 1, -1, 1, 15 ) > 0)
>  DECLARE INTEGER CloseHandle IN kernel32 INTEGER nHandle
>ENDIF
>IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'CreateProcess', 1, -1, 1, 15 ) > 0)
>  DECLARE INTEGER CreateProcess IN kernel32;
>          STRING lpAppName, STRING lpCmdLine, INTEGER lpProcAttr,;
>          INTEGER lpThrAttr, INTEGER bInhHandles, INTEGER dwCrFlags,;
>          INTEGER @lpEnvir, STRING lpCurDir, STRING lpStInfo,;
>          STRING @lpProcInfo
>ENDIF
>IF lnRes = 0 OR  NOT ( ASCAN( laJunk, 'WaitForSingleObject', 1, -1, 1, 15 ) > 0)
>  DECLARE INTEGER WaitForSingleObject IN kernel32;
>          INTEGER hHandle, INTEGER dwMilliseconds
>ENDIF
>
>***  The STARTUPINFO structure is used with the CreateProcess,
>***  CreateProcessAsUser, and CreateProcessWithLogonW functions
>***  to specify the window station, desktop, standard handles,
>***  and appearance of the main window for the new process.
>lcStartupInfo = CHR(68) + REPLICATE(CHR(0), 67)
>
>*** The PROCESS_INFORMATION structure is filled in
>*** by the CreateProcess function with information
>*** about a newly created process and its primary thread.
>lcProcInfo = REPLICATE(CHR(0), 16)
>
>IF CreateProcess( tcFileName, '', 0,0,0,0,0, CURDIR(),;
>                  lcStartupInfo, @lcProcInfo) # 0
>
>  *** retrieve handle for the new process by converting
>  *** the first four bytes in the structure to a DWORD
>  lnHandle = ASC(SUBSTR(lcProcInfo, 1, 1 ) ) + ;
>             ASC(SUBSTR(lcProcInfo, 2, 1 ) ) * 16^2 + ;
>             ASC(SUBSTR(lcProcInfo, 3, 1 ) ) * 16^4 + ;
>             ASC(SUBSTR(lcProcInfo, 4, 1 ) ) * 16^6
>
>  *** Now wait until it is finished
>  WaitForSingleObject ( lnHandle, INFINITE )
>  CloseHandle( lnHandle )
>ELSE
>  MESSAGEBOX( 'Unable to Create Process' + CHR( 13 ) +;
>              "Error code: " + TRANSFORM( GetLastError() ), 16, 'Major WAAHHHHH!!!!' )
>ENDIF
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform