Solved

DOS Doevents

Posted on 1998-10-28
6
477 Views
Last Modified: 2008-03-04
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 :)
0
Comment
Question by:wford
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 200 total points
ID: 1442121
'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
 
LVL 1

Author Comment

by:wford
ID: 1442122
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
 
LVL 15

Expert Comment

by:ameba
ID: 1442123
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 12

Expert Comment

by:mark2150
ID: 1442124
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
 
LVL 1

Author Comment

by:wford
ID: 1442125
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
 
LVL 1

Author Comment

by:wford
ID: 1442126
my colleage has gone on holidays...so instead mof allowing this to be auto graded, i will award the points..

Thanx all
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

623 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