Solved

Change ShellAndWait to not wait

Posted on 2014-07-19
2
166 Views
Last Modified: 2014-07-20
So I have the following function that works great:

Public Sub ShellAndWait(ByVal program_name As String, _
                         Optional ByVal window_style As VbAppWinStyle = vbNormalFocus, _
                         Optional ByVal max_wait_seconds As Long = 0)
    Dim lngProcessId As Long
    Dim lngProcessHandle As Long
    Dim datStartTime As Date
    Dim lngCursor As Long
    Const WAIT_TIMEOUT = &H102
    Const SYNCHRONIZE As Long = &H100000
    Const INFINITE As Long = &HFFFFFFFF

    lngCursor = Screen.MousePointer
    'Screen.'MousePointer = vbHourglass
    ' Start the program.
    On Error GoTo ShellError
    lngProcessId = Shell(program_name, window_style)
    On Error GoTo 0
    
    DoEvents

    ' Wait for the program to finish.
    ' Get the process handle.
    lngProcessHandle = OpenProcess(SYNCHRONIZE, 0, lngProcessId)
    If lngProcessHandle <> 0 Then
        datStartTime = Now
        Do
          If WaitForSingleObject(lngProcessHandle, 250) <> WAIT_TIMEOUT Then
            Exit Do
          End If
          DoEvents
          If max_wait_seconds > 0 Then
            If DateDiff("s", datStartTime, Now) > max_wait_seconds Then Exit Do
          End If
        Loop
        CloseHandle lngProcessHandle
    End If
    Screen.MousePointer = lngCursor
    
    Exit Sub
    
ShellError:
End Sub

Open in new window


I would like to change it so that it does the same thing but doesn't wait for the process to finish.  I still want it to finish, but in the background.  

Any ideas?
0
Comment
Question by:hrolsons
2 Comments
 
LVL 13

Assisted Solution

by:duncanb7
duncanb7 earned 250 total points
ID: 40207156
At this link, http://www.cpearson.com/excel/ShellAndWait.aspx
it mentions you can use Shell function to do command and don't wait for the command complete. Is Shell function what your want. The ShellAndWait function is target to improve Shell function to wait the command finish before go to next step

Actually, you can use Shell function that can be programmed to wait or not wait for comand complete , you can find it at Wait option from MS manual at  http://msdn.microsoft.com/en-us/library/xe736fyk(v=vs.90).aspx

Hope understand your question. If not , please point it out

Duncan
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 40207215
Simply call Shell alone instead of calling ShellAndWait:

Shell(program_name, window_style)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question