Science, Tech, Math › Computer Science How to Use Process.Start in Visual Basic Start another application using your .NET code Share Flipboard Email Print PhotoAlto/Sigrid Olsson/PhotoAlto Agency RF Collections/Getty Images Computer Science Visual Basic PHP Programming Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming View More By Dan Mabbutt Dan Mabbutt Computer Science Expert B.S., Computer Science, University of Utah Dan Mabbutt is a Visual Basic expert who created training courses for Visual Basic users. He co-authored two books on the subject. Learn about our Editorial Process Updated on February 04, 2019 The Start method of the Process object is possibly one of the most underappreciated tools available to a programmer. As a .NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts. What you can do with Process.Start is really only limited by the processes you can use with it. If you want to display your text-based ReadMe file in Notepad, it's as easy as: Process.Start("ReadMe.txt") Process.Start("notepad", "ReadMe.txt") This example assumes the ReadMe file is in the same folder as the program and that Notepad is the default application for .txt file types, and it's in the system environment path. Process.Start Similar to Shell Command in VB6 For programmers familiar with Visual Basic 6, Process.Start is somewhat like the VB 6 Shell command. In VB 6, you would use something like: lngPID = Shell("MyTextFile.txt", vbNormalFocus) Using Process.Start You can use this code to start Notepad maximized and create a ProcessStartInfo object that you can use for more precise control: Dim ProcessProperties As New ProcessStartInfoProcessProperties.FileName = "notepad"ProcessProperties.Arguments = "myTextFile.txt"ProcessProperties.WindowStyle = ProcessWindowStyle.MaximizedDim myProcess As Process = Process.Start(ProcessProperties) Starting a Hidden Process You can even start a hidden process. ProcessProperties.WindowStyle = ProcessWindowStyle.Hidden Retrieving the Name of a Process Working with Process.Start as a .NET object gives you a lot of capability. For example, you can retrieve the name of the process that was started. This code will display "notepad" in the output window: Dim myProcess As Process = Process.Start("MyTextFile.txt") Console.WriteLine(myProcess.ProcessName)This was something you could not do with the VB6 Shell command because it launched the new application asynchronously. Using WaitForExit can cause the reverse problem in .NET because you have to launch a process in a new thread if you need it to execute asynchronously. For example, if you need the components to remain active in a form where a process was launched and WaitForExit One way to force the process to halt is to use the Kill method. myProcess.Kill() This code waits for ten seconds and then ends the process. However, a forced delay is sometimes necessary to allow the process to complete exiting to avoid an error. myProcess.WaitForExit(10000)' if the process doesn't complete within' 10 seconds, kill itIf Not myProcess.HasExited ThenmyProcess.Kill()End IfThreading.Thread.Sleep(1)Console.WriteLine("Notepad ended: " _& myProcess.ExitTime & _Environment.NewLine & _"Exit Code: " & _myProcess.ExitCode) In most cases, it's probably a good idea to put your processing in a Using block to ensure that the resources used by the process are released. Using myProcess As Process = New Process' Your code goes hereEnd Using To make all this even easier to work with, there is even a Process component that you can add to your project so you can do a lot of the things shown above at design time instead of run time. One of the things that this makes a lot easier is coding events raised by the process, such as the event when the process has exited. You can also add a handler using code like this: ' allow the process to raise eventsmyProcess.EnableRaisingEvents = True' add an Exited event handlerAddHandler myProcess.Exited, _AddressOf Me.ProcessExitedPrivate Sub ProcessExited(ByVal sender As Object, _ByVal e As System.EventArgs)' Your code goes hereEnd Sub But simply selecting the event for the component is a lot easier. Cite this Article Format mla apa chicago Your Citation Mabbutt, Dan. "How to Use Process.Start in Visual Basic." ThoughtCo, Feb. 16, 2021, thoughtco.com/how-to-use-processstart-in-vbnet-3424455. Mabbutt, Dan. (2021, February 16). How to Use Process.Start in Visual Basic. Retrieved from https://www.thoughtco.com/how-to-use-processstart-in-vbnet-3424455 Mabbutt, Dan. "How to Use Process.Start in Visual Basic." ThoughtCo. https://www.thoughtco.com/how-to-use-processstart-in-vbnet-3424455 (accessed June 9, 2023). copy citation Featured Video