Results 1 to 3 of 3

Thread: Call a batch file from a command button...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    9

    Call a batch file from a command button...

    Hi all, I am very new to VB, and I have a button that I want to execute a command (batch file) from a file location, and once it launches the batch file I would like my VB program to close... Lets call the file CommandScript.cmd and the location is C:\MyFile

    Code:
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    
    
    ' Where the file is called and executed...this is where I am completely stuck
    
    
        End Sub
    End Class

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,289

    Re: Call a batch file from a command button...

    You can start a process to run the batch file and then close your application.
    Code:
    Process.Start("full path to the batch file here")
    Me.Close() '<<< Use this if your button is on the main form
    Application.Exit '<<< Or use this if your button is not on the main form.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Call a batch file from a command button...

    To open the bat file ...

    Process.Start("C:\MyFile\CommandScript.cmd")

    To close the VB program ... well, that's a matter of some dispute.

    Application.Exit

    .. is the quick and dirty method but you'll find at least a dozen different opinions on whether it's the best!

Tags for this Thread

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