Discussion Locked

Execute a EXE File on a button click

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I want to execute a EXE file on click event of a button in VB from any location of my HDD or CD-ROM. What will be the command (function)?

8 replies

by andrew

If just want to spawn another app, try this code:

Dim hTask As Double
hTask = Shell("c:\winnt\notepad.exe", vbNormalFocus)

Just replace the first parameter with the path and file name of the EXE you want to lauch. This will kick off the EXE and immediately return control to your app.

If you need to run the EXE synchronously (wait for it to end before your app continues) here's a link to a technique:

http://support.microsoft.com/support/kb/articles/Q129/7/96.asp

(make sure there are no spaces in the URL)

by chinmoy_b

I have done this...
##Dim hTask As Double
##hTask = Shell("c:\winnt\notepad.exe", vbNormalFocus)
But I want to publish a CD. Where the argument of SHELL will not be static (Like: "c:\winnt\notepad.exe"). What's the solution?

by mark.thomson

Change the string literal in the shell command to a string variable, which you can set any way you want eg From a dialogbox, registry setting, INI file etc

Dim hTask as Double
Dim sShellPath as string

sShellPath = "C:\winnt\notepad.exe"
'Could set this value from any number of 'sources
hTask= Shell(sShellPath, vbNormalFocus)

by andrew

Are you familiar with the concept of variables? It's used rather widely in software development.

Try:

Public Sub LaunchIt(sProgram as String)
Dim hTask As Double
hTask = Shell(sProgram, vbNormalFocus)
End Sub

Then pass in anything you want.

You can popup a dialog to ask the user, a file browsing dialog, read it from a command line...any way you want.

This discussion is closed to new replies.