Hi,
I wonder how i can execute another program from a vb program? Do i need a reference or something. Is there a file.execute method somewhere?
Printable View
Hi,
I wonder how i can execute another program from a vb program? Do i need a reference or something. Is there a file.execute method somewhere?
You can use the Shell function.
eg
Shell returns the programs ID if it is successful or 0 if it isn't. There are also options on how to load up the program (maximised, minimsed, etc).Code:Dim i as long
i=o
i = Shell("c:\calc.exe")
If i = 0 Then
MsgBox "Program startup failed"
End if
Sunny
Use the ShellExecute api function instead of Shell.
Code: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
Public Const SW_SHOWNORMAL = 1
Public Const SW_ShowMinimized = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_Hide = 0
ShellExecute Me.hwnd, vbNullString, "C:\file.exe", vbNullString, "c:\", SW_SHOWNORMAL