Monday, March 19, 2012

Launch a program from VB

An often requested task that new developers to VB ask is how can I write a program that will launch other programs. Its fun to create your own little launcher program that does things like allows you to quickly launch just the programs you want. Obviously program launchers already exist out on the market that you could simply use. But one of the great things about learning a programming language like Visual Basic is that you can create your own programs that behave exactly how you want them to.

To try out the this sample source code snippet simply create a VB project, add a command button to the main form, double click this button to get into the click event handler for it and add the following code.

    Filename = "C:\windows\notepad.exe" 'Check file is here first    MsgBox Filename & " not found", vbInformation    Res = Shell("Start.exe " & Filename, vbHide)

This source code uses the VB6 Shell command to launch a new program. We specifically call the Start.exe program as it can be used to launch other programs easily.

Note: The source for this was found at DreamVB which is no longer online.


View the original article here

No comments:

Post a Comment