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

 

Code Snippets

  

Visual Basic Source Code


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

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





Starting an *.exe file from VB6 code

This is a simple line of code to run a .exe application from VB6.

Submitted By: Xenon
Actions:
Rating:
Views: 41,055

Language: Visual Basic

Last Modified: October 27, 2005
Instructions: take a form and add a command button to it, name it as cmdExec.

Snippet


  1. 'I have made the code to run the calculator, which
  2. ' is present in every Windows Based PC.
  3. 'the command button  click() event triggers
  4. 'the application to run.
  5.  
  6. 'General Syntax is
  7. RetVal = Shell([Pathname of EXE],[WindowStyle As vbAppWinStyle = vbMinimisedFocus])
  8. '----------------CODE--------------------
  9. Private Sub cmdExec_Click() ' cmdExec is the name of the command button on any form.
  10. Dim RetVal
  11. RetVal = Shell("C:\WINDOWS\System32\calc.exe", 1)    ' Run Calculator.
  12.  
  13. End Sub
  14. '---------------------------------------

Copy & Paste


Comments


denmont 2007-11-06 20:22:26

i would like to use a variable in place of a hard code file name. example: MyFile as String MyFile = "drawing.3dm" call shell("c:\rhino.exe c:\MyFile",3)

vishnudba 2008-04-24 07:01:11

Will it work for all exes

Jaalenn 2008-11-20 01:00:30

To answer this old question, yes. All you have to do is change RetVal = Shell("C:\WINDOWS\System32\calc.exe", 1) to RetVal = Shell("C:\File Location\Filename.exe", 1) Be sure to substitute the proper filepath for your exe.

Redalps_fox 2009-02-15 19:02:21

how will call my exe file from a cdrom? how will i use path to call my exe file in cdrom. sory poor english. please send to my email rauleroy@yahoo.com. thanks advance

2009-06-22 06:28:32

how do i can send "Ctrl+S" to an open exe file by sendkeys function?

avijit_g 2009-07-22 07:06:06

Thats Great, all the command are true & working with VB

shashankc 2009-08-18 18:43:00

what if i have to form any exe icon..it will also work


Add comment


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





Live VB Help!

Be Social

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

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month