Code Snippets

  

Visual Basic Source Code


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

Join 148,644 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,383 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: 25,186

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.


Add comment


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




Be Social

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

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month