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
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.
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!