title: Run a batch program(.bat) through a Visual Basic 6.0
body: <p>I want to run a batch program(.bat) through a Visual Basic 6.0 application and also want to print the output of the batch program(.bat) in the Visual Basic 6.0 application. I want to execute the <strong>dir</strong> command in the batch file so that VB6.0 application can print the output in a text box. </p>
  
  <p>VB6.0 code:</p>
  
  <pre><code>Dim com As String
  Dim wshThisShell
  Dim lngRet As Long
  Dim strShellCommand As String
  Dim strBatchPath As String
  
  Sub C0ding()
      Set wshThisShell = CreateObject("WScript.Shell")
      strBatchPath = "C:\first.bat"
      strShellCommand = """" &amp; strBatchPath &amp; """"
      lngRet = wshThisShell.Run(strShellCommand, vbNormalFocus, vbTrue)
  End Sub
  
  Private Sub Command1_Click()
      C0ding
  End Sub
  </code></pre>
  
  <p>first.bat:</p>
  
  <pre><code>dir c:\
  </code></pre>
  
  <p>In the above example '<strong>first.bat</strong>' is batch file and containing the 'dir c:\' command. Now VB6.0 app will run the first.bat and show the output of the 'dir c:\' command in a text box.</p>
  
  <p>Please also tell me that I can achieve this requirement means can VB6.0 application regain the control from batch program(.bat)?</p>
  
  <p>Please help me with this.</p>