Solved

DOS Doevents

Posted on 1998-10-28
6
451 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

773 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