Solved

Vb5 with batch files

Posted on 1998-10-22
4
345 Views
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

Thank
Eric Bouchard
0
Comment
Question by:ceb102298
  • 2
4 Comments
 
LVL 3

Expert Comment

by:vmano
ID: 1441208
use Sleep API in between those two calls.
0
 
LVL 3

Expert Comment

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

in the code:
Sleep(1000) 'in milliseconds
0
 
LVL 8

Accepted Solution

by:
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



0
 

Expert Comment

by:stane
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.

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

      Dim proc As PROCESS_INFORMATION
      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
Form1:

Sub Form_Click ()

      ExecCmd "notepad.exe"
      MsgBox "Process Finished"



End Sub
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

747 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

8 Experts available now in Live!

Get 1:1 Help Now