How can i call a exe file in visual basic, to execute it.
Printable View
How can i call a exe file in visual basic, to execute it.
Dim r As Long
lblCurrentPath.Caption = lblCurrentPath.Caption + "\" + cboSelection.Text
r = StartDoc(lblCurrentPath.Caption)
Dim RetVal as Long
RetVal = Shell("C:\MyDirectory\My.exe", vbNormalFocus)
It is best to use the ShellExecute api function. This is good because it will load any program no matter what. Whereas the regular Shell function may cause an error if it cannot load the file or if it doesn't exist.
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
ShellExecute Me.hwnd, vbNullString, "C:\file.exe", vbNullString, "c:\", SW_SHOWNORMAL