How can i run a file with its associated app, like the Run dialog does? Its for a voice recognition project im working on, you tell it that when you say something, it can run a file or run a built in function?
Thanx!
Printable View
How can i run a file with its associated app, like the Run dialog does? Its for a voice recognition project im working on, you tell it that when you say something, it can run a file or run a built in function?
Thanx!
You can use the ShellExecute API function to do this.
VB 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 Private Sub OpenFile(sFile As String) ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, 1 End Sub Private Sub Command1_Click() Call OpenFile("C:\MyFile.txt") End Sub
thanx m8
How do i get the Focus to come to the app just launched, like with x=Shell then u just put vbNormalFocus, but how do i do this herE?
It's already there.
VB Code:
Private Sub OpenFile(sFile As String) ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, 1 End Sub
It's the 1 at the end. I put a 1 instead of the vbNormalFocus constant.
If you wish the change it, you'll get the same result.
VB Code:
Private Sub OpenFile(sFile As String) ShellExecute Me.hwnd, vbNullString, sFile, vbNullString, vbNullString, vbNormalFocus End Sub