8

Basically, what I want to do is launch an *.exe file when I click on a button. I want this done in VB.NET. I have Microsoft Visual Basic 2008 Express Edition.

The button I have is called 'btnYES'.

How can I launch an *.exe file from the click of this button?

John Saunders
  • 157,405
  • 24
  • 229
  • 388
Computeristic
  • 107
  • 1
  • 2
  • 8

2 Answers2

28

In the event handler of the button call

Process.Start("C:\path_to\myapp.exe")

You will find further samples in the MSDN documentation for Process.Start().

In case you don't know how an event handler is created: Simply open the form in the designer and double-click on the btnYes button. This will automatically create an event handler for the button click event and the IDE will open the code file for you at the correct position.

Dirk Vollmar
  • 161,833
  • 52
  • 243
  • 303
  • Thank you for the tip of this Process.Start() code! However, I do know that if you double click on the button, it will take me to the code for that particaular thing clicked on, in this case my btnYES button! But thanks! :D – Computeristic Apr 13 '10 at 16:27
  • 1
    this helped me alot, however if I were to share this program with someone who didn't have the same username as me, how would this work –  Oct 05 '16 at 22:32
5

If you want to call an exe file by code:

  1. If the file is a single file do the following:

    Process.Start("D:\MATI2\MATI.EXE")
    

You can obtain the path by right click the exe file while pressing shift and choosing copy as path

  1. If the file is dependent on one or more .dll files the previous way will not work, use the following:

    Dim info As New ProcessStartInfo()
    info.FileName = "C:\Program Files (x86)\VentSrv\ventrilo_srv.exe"
    info.WorkingDirectory = "C:\Program Files (x86)\VentSrv"
    info.Arguments = "<specify the command line arguments here if necessary>"
    Process.Start(info)
    
8bittree
  • 1,619
  • 1
  • 17
  • 22
ezzsakr
  • 51
  • 1
  • 1