Solved

DOS Doevents

Posted on 1998-10-28
6
439 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
Comment Utility
'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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 12

Expert Comment

by:mark2150
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now