DOS Doevents

We want to run a DOS program, which is run using shell.
The Dos program takes about a minute or so to process, at the end of this DOS process, we want the VB function to continue on to the next line.

We have other processes running at the same time both on the computer and in the VB application, and need them to keep running while this process is doing its work.
we cannot edit the DOS program, but have a batch file which runs it.

So we need the code that goes here
private sub fn_shell()
n = Shell(MyBatchFileName)
....
....
'process to be done AFTER the Dos Process is Done
call fn_SuchAndSuch
End Sub

*PLEASE NOTE: the process is not the successfull starting of the DOS shell, nor even the dos exe running, it is the completion of the DOS program.

At the moment we have a dummy marker file that is created at the end of the batch file, and this file is searched for in a loop until It finds the file, which breaks the loop and continues the function, So, we don't want this solution :)
LVL 1
wfordAsked:
Who is Participating?
 
deightonConnect With a Mentor Commented:
'ExecCmd is the function e.g. call ExecCmd("c:\temp\bat.bat")
'Make this into a .BAS module

Option Explicit

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function GetModuleUsage Lib "kernel32" (ByVal hModule As Integer) As Integer






      Private Type STARTUPINFO

         cb As Long
         lpReserved As String
         lpDesktop As String
         lpTitle As String
         dwX As Long
         dwY As Long
         dwXSize As Long
         dwYSize As Long
         dwXCountChars As Long
         dwYCountChars As Long
         dwFillAttribute As Long
         dwFlags As Long
         wShowWindow As Integer
         cbReserved2 As Integer
         lpReserved2 As Long
         hStdInput As Long
         hStdOutput As Long
         hStdError As Long
      End Type

      Private Type PROCESS_INFORMATION
         hProcess As Long
         hThread As Long
         dwProcessID As Long
         dwThreadID As Long
      End Type

      Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
         hHandle As Long, ByVal dwMilliseconds As Long) As Long

      Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
         lpApplicationName As Long, ByVal lpCommandLine As String, ByVal _
         lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
         ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
         ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, _
         lpStartupInfo As STARTUPINFO, lpProcessInformation As _
         PROCESS_INFORMATION) As Long

      Private Declare Function CloseHandle Lib "kernel32" (ByVal _
         hObject As Long) As Long

      Private Const NORMAL_PRIORITY_CLASS = &H20&
      Private Const INFINITE = -1&


      Public Sub ExecCmd(cmdline As String)
         Dim proc As PROCESS_INFORMATION
         Dim start As STARTUPINFO
         Dim ret As Long

         ' Initialize the STARTUPINFO structure:
         start.cb = Len(start)

         ' Start the shelled application:
         ret = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
            NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

         ' Wait for the shelled application to finish:
         ret = WaitForSingleObject(proc.hProcess, INFINITE)
         ret = CloseHandle(proc.hProcess)
      End Sub





0
 
wfordAuthor Commented:
Thanks, I will have a look at this tomorrow, If anyone else has a different suggestion, post it as a comment and I'll see which works.
0
 
amebaCommented:
I think this might be for you:

' Shell32.Bas, Copyright ©1996 Karl E. Peterson
' Free use permitted, with attribution for source.
****************************************************************
' Three methods to "Shell and Wait" under Win32.
' One deals with the infamous "Finished" behavior of Win95.

1.
Public Function ShellAndClose(ByVal JobToDo As String, Optional ExecMode) As Long
   '
   ' Shells a new process and waits for it to complete.
   ' Calling application is responsive while new process
   ' executes. It will react to new events, though execution
   ' of the current thread will not continue.
   '
   ' Will close a DOS box when Win95 doesn't. More overhead
   ' than ShellAndLoop but useful when needed.

2.
Public Function ShellAndLoop(ByVal JobToDo As String, Optional ExecMode) As Long
   '
   ' Shells a new process and waits for it to complete.
   ' Calling application is responsive while new process
   ' executes. It will react to new events, though execution
   ' of the current thread will not continue.
   '

3.
Public Function ShellAndWait(ByVal JobToDo As String, Optional ExecMode, Optional TimeOut) As Long
   '
   ' Shells a new process and waits for it to complete.
   ' Calling application is totally non-responsive while
   ' new process executes.
   '

Link:
http://www.mvps.org/vb/code/shell32.zip
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mark2150Commented:
One operational note on ExecCmd. You need to adjust the properties page of the program you're shelling to so that it has "Run Minimized" and "Close on Exit" to make it a "silent runner".

M

0
 
wfordAuthor Commented:
have not forgotten, my colleage has not tested this solution yet, so as soon as he does, i'll get back to you guys ;o)
0
 
wfordAuthor Commented:
my colleage has gone on holidays...so instead mof allowing this to be auto graded, i will award the points..

Thanx all
0
All Courses

From novice to tech pro — start learning today.