Results 1 to 6 of 6

Thread: open batch file

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10

    Cool

    hi,pls help this newly member here.

    How to open .bat files using VB.
    (similar as manually double clicking the batch file in the C directory explorer)
    thanx!


  2. #2
    Guest
    Use the Shell function.

    Code:
    Shell "C:\MyBatch.bat",vbNormalFocus

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10
    i tried your code, but still not responsed.
    the idea to execute the batch file is to send a signal command to COM1 port & this command is written in a text file.& the batch file used to copy the text file to COM1.

    This signal is to kick out the cash drawer machine.

    I tried double click the 1.bat & it's works

    ??? how to put it into VB?

  4. #4
    Guest
    There appears to be nothing wrong with Matthew's code. Perhaps you can try to shell something else first.

    Code:
    Shell "C:\Windows\Calc.exe", vbNormalFocus
    This should start up calculator.

    Sunny

  5. #5
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up ShellExecute API

    Hi shwan, may be you can try to use this code, & I've test it. It work as what you ask for.

    Code:
    Option Explicit
    Private Const SW_HIDE = 0
    Private Const SW_SHOWNORMAL = 1
    Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    Private Sub Command1_Click()
    'To execute the batch file with loading the MS-Dos Command window
    ShellExecute Me.hwnd, vbNullString, "C:\MyBatch.bat", vbNullString, "C:\", SW_SHOWNORMAL
    'To execute the batch file without loading the MS-Dos Command window
    ShellExecute Me.hwnd, vbNullString, "C:\MyBatch.bat", vbNullString, "C:\", SW_HIDE
    End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    10
    hi,it's works...finally!
    thanx everyone!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width