Brian Rathbone wrote:

I'll send you my CreateProcess "shell and wait" example off list to get you started.

Actually, I found an example I had done that is simple enough to share on the list...

The command line can contain just the name of an app, document or URL that is in the path, the full path to an app or document, and even the parameters you wish to pass to the app. Basically, if the command works in the Windows "Run" command, it should work as the command line for this function.


Function ShellWaitAsynchronous(sInCommandline as String, Visible as Boolean) As Boolean ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// This function can be used to launch another application and wait for it to terminate
 /// Application can be launched visibly or invisibly.
/// Move WaitForSingleObject calls to a timer for GUI apps instead of using sleep /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 #if targetWin32 then

Declare Function CreateProcessA Lib "kernel32" (lpApplicationName As integer, lpCommandLine As cString, lpProcessAttributes As integer, lpThreadAttributes As integer, bInheritHandles As integer, dwCreationFlags As integer, lpEnvironment As integer, lpCurrentDirectory As cstring, lpStartupInfo As ptr, lpProcessInformation As ptr) As integer

Declare Sub Sleep Lib "kernel32" Alias "Sleep" (dwMilliseconds As integer)

Declare Function WaitForSingleObject Lib "kernel32" (hHandle As integer, dwMilliseconds As integer) As integer

Declare Function CloseHandle Lib "kernel32" (hObject As integer) As integer Const SW_HIDE = 0
   Const SW_SHOWNORMAL = 1
   Const WAIT_OBJECT_0 = 0
   Const WAIT_TIMEOUT = &H102
   Const NORMAL_PRIORITY_CLASS = &H20
Dim Ret As integer
   Dim StartInf As memoryblock
   Dim Proc as MemoryBlock
Startinf = newmemoryBlock(76)
   Startinf.long(44) = 1 /// set flags to use showwindow
   If Visible then
     Startinf.long(48) = SW_SHOWNORMAL
   Else
     Startinf.long(48) = SW_HIDE
   End
   Proc = newmemoryBlock(16)
   StartInf.long(0) = StartInf.size
Ret = CreateProcessA(0,sInCommandline, 0, 0, 1,NORMAL_PRIORITY_CLASS, 0, "C:\", StartInf, Proc) //replace C:\ with your desired working directory
    If Ret <> 0 then
     ///////////////////////////////////////
     /// For GUI apps, place this code in a timer rather than using sleep
     ///////////////////////////////////////
     Do
Ret = WaitForSingleObject(proc.long(0), 300) /// longer than 5000 will cause app to show as 'not responding' in the task list
       if Ret = WAIT_OBJECT_0 then
         /// Application has terminated
         Ret = CloseHandle(proc.long(0))
         return true
       elseif Ret = WAIT_TIMEOUT then
         /// keep waiting
       else
         Ret = CloseHandle(proc.long(0))
         return false
       end
       Sleep(300)
     Loop
   Else
     /// bad command line
     return false
   End
 #endif
End Function


hth,

Brian


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to