Launch a program from VB

Level:
Level1

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.

  1. Dim Res
  2. Dim Filename
  3.     Filename = "C:\windows\notepad.exe" 'Check file is here first
  4. If Dir(Filename) = "" Then
  5.     MsgBox Filename & " not found", vbInformation
  6. Else
  7.     Res = Shell("Start.exe " & Filename, vbHide)
  8. End If

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.

If you enjoyed this post, subscribe for updates (it's free)

protect application programe of visual basic from coping

I need a code programing to protect my visual basic application from copying

protect file from coping

I need visual basic code to protect my application program from copng

SMS

pls how can i use bulk sms in vb6

launch program from vb

how to launch ms.word from vb

Executing notepad

Thanks, I made a little change:

Dim Res
Dim Filename
Filename = "C:\windows\notepad.exe" 'Check file is here first
If Dir(Filename) = "" Then
MsgBox Filename & " not found", vbInformation
Else
Res = Shell(Filename, vbNormalFocus)
End If

Thanks Kmilo....your code is

Thanks Kmilo....your code is working!

Command Line Arguments

How can i start a program with command line arguments?

Nice

nice.but can you give me simple database for attendance for example.....

Listbox Item Adding In MS Access Database

I m creating a small application which have a combobox & listbox & two button add & remove with ms access database.
Add button simply add item of combobox in to listbox
& remove button simply remove the item from listbox.
Now i wnat to insert items of listbox in database.
Single item is inserted but multiple is not inserted.
any one can have any idea...........

how can i lunch programs

how can i lunch programs without given the address? i mean can i lunch them from my program folder so and no need to know the proper address,

vb6

can u give me a sample prog like a
1. count down log-in?
2. grading sheet
3. lucky 7
ty

this wil work

change :
Res = Shell("Start.exe " & Filename, vbHide) Change Start.exe into Explorer.exe BV, then the program wil open notepad.

This example worked.. Final

This example worked.. Final code
Dim Res
Dim Filename
Filename = "C:\windows\notepad.exe" 'Check file is here first
If Dir(Filename) = "" Then
MsgBox Filename & " not found", vbInformation
Else
Res = Shell("Explorer.exe " & Filename, vbHide)
End If

in Res = Shell("program that

in Res = Shell("program that u wanna open/link " & Filename, vbHide), try to remove "& filename"... it'll work ^^

Video Rental

Sir/Ma'am

Please help me on how to make a video rental in my activity in our school...
because i don't know how to make it...
please....please....help me......:)

Please tell me how to put

Please tell me how to put install option in a program made by me in VB6, as it happens in real life programs.

maybe it can help u!!

change :
Res = Shell("Start.exe " & Filename, vbHide) become Res = Shell("program that u wanna open/link " & Filename, vbHide)

query

it doesnt work on my pc, can you help me?... when i run the program and click the command button it says that file is not found. runtime error 53.

reply

Check to make sure the path

Check to make sure the path name you have chosen for the project to run is the actual path name the program is located in. You can add an I/O exception that checks for potential path validation issues by creating a "try" clause that procedes the file execution code.

it doesnt work

it doesnt work on my pc, can you help me?... when i run the program and click the command button it says that file is not found. runtime error 53.

would it kill people to

would it kill people to break down the code for once its no good just having little snippits here and there