Results 1 to 5 of 5

Thread: Synchronous execution of command

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    13

    Synchronous execution of command

    I am using the Shell command to start a batch file; however I want to wait for the process to complete before moving on to the next line of code. How can I do this?

  2. #2
    Addicted Member
    Join Date
    Apr 2000
    Location
    England
    Posts
    246
    Find the Batch process, and wait till it stops, or make the batch file output a file (echo Finished > %windir%\temp\finished.txt) and then delete that file
    Some Days, i just get this feeling that i'm helping to write dozens of Viruses...

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    13
    Can you show me how? Does it have something to do w/ the task number returned by the Shell function? I don't want to output a file, because the program could execute concurrently on multiple machines (it is a software audit program that runs on multiple machines on our network). Thank you!

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    put this code in a bas module;
    Code:
    Const INFINITE = -1&
    Const SYNCHRONIZE = &H100000
    Declare Function WaitForSingleObject Lib "kernel32" _
       (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
    
    Declare Function CloseHandle Lib "kernel32" _
       (ByVal hObject As Long) As Long
       
    Declare Function OpenProcess Lib "kernel32" _
       (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
        ByVal dwProcessId As Long) As Long
    and use this to run the bat file
    Code:
    dim lngtask as long
    dim phandle as long
    dim ret as long
      itask = Shell("mybat.bat")
        pHandle = OpenProcess(SYNCHRONIZE, False, itask)
        ret = WaitForSingleObject(pHandle, INFINITE)
        ret = CloseHandle(pHandle)
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2001
    Posts
    13
    Thank you both very much for the *quick* replies!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width