Hi there,
I' ve searched several documentation but I wasn't able to find solutions.
How could I start a program from my VB-app.
Printable View
Hi there,
I' ve searched several documentation but I wasn't able to find solutions.
How could I start a program from my VB-app.
Code:Shell "whatever.exe"
use the shell command
e.g
You can also chose how the application is displayed when it is started.Code:Shell "C:\MYPROG.EXE"
The following constants can be used for this.
vbHide --- Window is hidden and focus is passed to the hidden window.
vbNormalFocus --- Window has focus and is restored to its original size and position.
vbMinimizedFocus --- Window is displayed as an icon with focus.
vbMaximizedFocus --- Window is maximized with focus.
vbNormalNoFocus --- Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus --- Window is displayed as an icon. The currently active window remains active.
If you want to use this aswell, the command would be as follows
Hope this helpsCode:Shell ("C:\MYPROG.EXE", vbMaximizedFocus)
thx @all
The Shell function will basically load any exe, but not any other files. Instead, you should use the ShellExecute function.
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
Public Const SW_MAX = 10
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_NORMAL = 1
ShellExecute Me.hwnd, vbNullString, "C:\txtfile.txt", vbNullString, "c:\", SW_SHOWNORMAL
Likewise, you can use the Shell method to open a file.
Code:Shell "Notepad C:\Windows\Desktop\ttt.txt", vbNormalFocus
If you're sure that the application exists.
It's very easy to tell if an application exists:
Code:ffile = Dir("C:\file.exe")
'returns "" if file doesn't exist
'returns "C:\file.exe" if file does exist
If Not ffile = "" Then
'Shell the program
Else
Msgbox "File doesn't exist!", 16
End If
I think your first code was probably better, because it uses Windows' own associations to open the file.