Vb5 with batch files

Posted on 1998-10-22
Last Modified: 2010-04-30
I have a pc with win95 and VB5. I have an application in Vb5 and i want to execute 2 batch files one after an other.

I execute this line: Call Shell("C:\M.bat", 1)
                              Call Shell("C:\P.bat", 1)

But this 2 program are execute in the same time.

What is the solution

Eric Bouchard
Question by:ceb102298
  • 2

Expert Comment

ID: 1441208
use Sleep API in between those two calls.

Expert Comment

ID: 1441209
in the module:
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

in the code:
Sleep(1000) 'in milliseconds

Accepted Solution

MikeP090797 earned 200 total points
ID: 1441210
Create a third .bat file, make it call the other two one after another. It won't be so hard to generate the .bat file from code, or even combine them into one

'To Call the other .bat files:
Open "C:\Result.Bat" for output as #1
Print #1, "C:\1.Bat"
Print #2, "C:\2.Bat"
Close #1


Expert Comment

ID: 1441211
Executing the Shell() function in a Visual Basic for Windows program
starts another executable program asynchronously and returns control to
the Visual Basic application. This shelled program continues to run
independent of your application until the user closes it. If you are running
DOS batch file use Close on exit.


      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


      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 _

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$)

      Dim start As STARTUPINFO

      ' 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 3.Add the following code the Form_Click() event procedure of

Sub Form_Click ()

      ExecCmd "notepad.exe"
      MsgBox "Process Finished"

End Sub

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
bit defender blocks good applications 2 101
Sending a email via excel using vba 6 97
Visual Studio 2005 text editor 10 44
Added a column screws up code 5 63
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

839 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