VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,308 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,103 people online right now. Registration is fast and FREE... Join Now!





Running an external executable file

This will allow you to start an executable application from within VB.NET. You can also use to open a file with its associated executable (ie. open a .doc file with MS Word)

Submitted By: Jayman
Actions:
Rating:
Views: 29,705

Language: VB.NET

Last Modified: August 9, 2006
Instructions: Make you sure you import the following for this to work:

Imports System.Diagnostics.Process

Snippet


  1. 'make a call to your application or file by giving Process.Start
  2. 'the full path to your file including name and extension.
  3.  
  4. 'will open a Word document called myfile.doc with MS Word
  5. Process.Start("c:\myTestFolder\myfile.doc")
  6.  
  7. 'will run an executable file called myfile.exe
  8. Process.Start("c:\myTestFolder\myfile.exe")
  9.  
  10. 'will open a blank notepad
  11. Process.Start("Notepad.exe")
  12.  
  13. 'I'm sure you get the idea
  14.  

Copy & Paste


Comments


Matthew Blanch 2008-08-18 19:44:23

Thank you so much for this code snippet!!!!! I have been trying to find out how this for a long time and had not found anything. Now i know how to do it! Thank you! Matthew Blanch.

Rozie0910 2008-10-14 01:48:04

i try to open test file on c but i can't could any want help me.. Dim RetVal As String RetVal = Shell("C:\test.exe", 1)

XedinUnknown 2008-11-27 06:48:35

Nice! Thanks.

RonK 2009-05-05 08:40:39

Yes but how about adding conditions? In 1.1 I could write: Dim startexe as New Process startexe.Startinfo.WindowStyle = ProcessWindowStyle.Hidden startexe.Start(getrootPath + "myexe.exe") However, 2.0 does not like "startexe.Start(..." How do I do the equivalent?

suchin 2009-05-05 23:35:39

test

DreamHer 2009-05-06 14:39:06

Like Matthew Blanch I searched a couple of hours and gave up, when back to search I found your code. Many thanks.

Jayman 2009-05-06 21:42:12

Ronk, I would start by checking the value of getrootPath and make sure that it when combined with the EXE name is a valid path. The Start method of the Process class is valid in 2.0, so your implementation is correct. If you are still having trouble, post your question in the forums with all your code and we will help you get it working.

ronzo 2009-09-10 00:46:10

Thanks, just what I needed to launch programs from my list box of filenames. I did not need to include "Imports System.Diagnostics.Process" in order to get it to work in my VB.Net 2005 project. The only namespace I import is System.IO and it opened any file I selected.


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month