How to run batch file in DOS window 
Author Message
 How to run batch file in DOS window

I have a file called "READ.BAT" and I would like to run it from VB and have
it execute in a DOS window.  How do Ido that


Sat, 12 Jul 2003 11:13:20 GMT  
 How to run batch file in DOS window
Use the shell command ?


Quote:
> I have a file called "READ.BAT" and I would like to run it from VB and
have
> it execute in a DOS window.  How do Ido that



Sun, 13 Jul 2003 11:51:23 GMT  
 How to run batch file in DOS window
The old Chestnut again :-

Option Explicit

'To Kill a DOS app: Jason Bouzane

Private Declare Function WaitForSingleObject Lib "kernel32" _
      (ByVal hHandle As Long, ByVal dwMilliseconds As Long) _
      As Long
Private Declare Function OpenProcess Lib "kernel32" _
      (ByVal dwDesiredAccess As Long, _
       ByVal bInheritHandle As Long, _
       ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
      (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" _
       (ByVal hProcess As Long, _
        ByVal uExitCode As Long) As Long

Private Const SYNCHRONIZE = &H100000
Private Const WAIT_TIMEOUT = &H102
Private Const PROCESS_TERMINATE = &H1

Sub CallDos(Cmd$)

    Dim hProcess As Long
    Dim pID As Long
    Dim lRet As Long
    Dim Style As Integer
    Dim TimeOutSecs As Long

    TimeOutSecs = 6
    ' Style = vbHide
    Style = vbNormalFocus

    pID = Shell(Environ("Comspec") + " /C " + Cmd, Style)
    hProcess = OpenProcess(SYNCHRONIZE, False, pID)
    lRet = WaitForSingleObject(hProcess, TimeOutSecs * 1000)

    If lRet = WAIT_TIMEOUT Then
        CloseHandle hProcess
        hProcess = OpenProcess(PROCESS_TERMINATE, False, pID)
        If hProcess = 0 Then Exit Sub
        TerminateProcess hProcess, 0
        CloseHandle hProcess
    End If

End Sub

Private Sub Command1_Click()
    CallDos "DIR C:\ /P"
    MsgBox "I GOT BACK"
End Sub

On Tue, 23 Jan 2001 22:51:23 -0500, "Christopher H"

Quote:

>Use the shell command ?



>> I have a file called "READ.BAT" and I would like to run it from VB and
>have
>> it execute in a DOS window.  How do Ido that



Mon, 14 Jul 2003 03:15:50 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help: hiding a DOS window when executing a DOS batch file

2. question on hiding a DOS window when executing a DOS batch file

3. Running DOS Batch file (in WinNT) from VB3

4. Running DOS Batch File

5. running multiple dos batch files from VB...

6. How to run my dos batch file fro visual basic

7. How to run a dos batch file from VB5

8. Running a DOS batch file from VB?

9. Dos batch file for windows

10. Closing those minimized windows after running a shell batch file

11. DOS Batch File to Copy Files from an Access Application

12. Bad Command or File name when Shelling DOS Batch File

 

 
Powered by phpBB® Forum Software