Link to home
Start Free TrialLog in
Avatar of djiangr
djiangr

asked on

in VB6 what is code to run another .exe file?

in VB6 what is code to run another .exe file?
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
in other words:

Shell "MyOtherExe.exe"
Shell

example
Shell "notepad.exe"

will spawn a notepad :-)

there are other methods ofcourse, but the above is built in and easy....

have Fun!
Pratap
aww... too late..
Avatar of fatalXception
fatalXception

try
shell full path to .exe, focusFlag

e.g
shell "c:\progs\myprog.exe -arg1 -arg2", vbNormalFocus

if I recall  correctly
You might want to have a look at this for an alternative:
http://www.freevbcode.com/ShowCode.asp?ID=264
Use the Shell function like so:
Shell(pathname[,windowstyle])

You can find full documentation for the function at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbenlr98/html/vafctShell.asp

I hope this helps.
Hey u can use this API's

---------------------------------------------------------------------------------------------------------
Program 1 using ShellExecute

The ShellExecute function opens or prints a specified file. The file can be an executable file or a document file.

Code :

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
Private Sub Form_Load()
    'Send an E-Mail to the KPD-Team
    ShellExecute Me.hwnd, vbNullString, "mailto:KPDTeam@Allapi.net", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
---------------------------------------------------------------------------------------------------------
Program 2 using ShellExecuteEx

The ShellExecuteEx function performs an action on a file. The file can be an executable file or a document.

Code :

Const SEE_MASK_INVOKEIDLIST = &HC
Const SEE_MASK_NOCLOSEPROCESS = &H40
Const SEE_MASK_FLAG_NO_UI = &H400
Private Type SHELLEXECUTEINFO
    cbSize As Long
    fMask As Long
    hwnd As Long
    lpVerb As String
    lpFile As String
    lpParameters As String
    lpDirectory As String
    nShow As Long
    hInstApp As Long
    lpIDList As Long
    lpClass As String
    hkeyClass As Long
    dwHotKey As Long
    hIcon As Long
    hProcess As Long
End Type
Private Declare Function ShellExecuteEx Lib "shell32.dll" Alias "ShellExecuteEx" (SEI As SHELLEXECUTEINFO) As Long
Sub ShowProps(FileName As String, OwnerhWnd As Long)
    Dim SEI As SHELLEXECUTEINFO
    Dim r As Long
    With SEI
        'Set the structure's size
        .cbSize = Len(SEI)
        'Seet the mask
        .fMask = SEE_MASK_NOCLOSEPROCESS Or _
         SEE_MASK_INVOKEIDLIST Or SEE_MASK_FLAG_NO_UI
        'Set the owner window
        .hwnd = OwnerhWnd
        'Show the properties
        .lpVerb = "properties"
        'Set the filename
        .lpFile = FileName
        .lpParameters = vbNullChar
        .lpDirectory = vbNullChar
        .nShow = 0
        .hInstApp = 0
        .lpIDList = 0
    End With
    r = ShellExecuteEX(SEI)
End Sub
Private Sub Form_Load()
    ShowProps "c:\config.sys", Me.hwnd
End Sub
---------------------------------------------------------------------------------------------

Hope you will find this code useful.......Bye

Jagadeesh
In addition to the methods the other experts have shown/referenced above, there is another code reference you might want to check out...

      http://www.freevbcode.com/ShowCode.Asp?ID=99

This reference demonstrates, in about 40 lines of code, how to invoke another application and wait til it finishes before continuing.  Those cited above spawn the new app to run asynchronously.  
ahem.. isnt all this too much complexity for a simple question!! for a beginner level the first couple of answers should be good enough.. IMHO
Nah.. a beginner should look at the options and get a idea of what's going to occur.. maybe he's a fast learner ;)
oh well.. no harm done.. :-)
djiangr - Once you get the hang of Shell, learn the FileSystemObject object model.  You can do all sorts of neat-o stuff with folders and files without doing a lot of code.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconprogramminginfsoobjectmodel.asp

Thanks for the points.
-Jim