[RESOLVED] Shell Execute with Commands...
VB6
Windows 10
Declarations
Code:
#If Win32 Then
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
Declare Function GetDesktopWindow Lib "USER32" () As Long
#Else
Declare Function ShellExecute Lib "SHELL" (ByVal hwnd%, _
ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, _
ByVal LpszDir$, ByVal FsShowCmd%) As Integer
Declare Function GetDesktopWindow Lib "USER" () As Integer
#End If
Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Function
Code:
Function OpenFile(sFile As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", sFile, "", "C:\", SW_SHOWNORMAL)
End Function
The command/parameters when loading vlc this way is to stop the video after 30 seconds. The playlist entry has been checked to work using the Windows Run Box. This does not open vlc at all.
Code:
OpenFile "vlc --stop-time 30 " & lstPlaylist.List(lstPlaylist.ListCount - 1)
This, however, loads vlc with no problem.
My question is: How can I load vlc with the commands/parameters?
Re: Shell Execute with Commands...
Pass the parameters to the lpParameters parameter. Right now you are passing an empty string for the parameters.
Re: Shell Execute with Commands...
My calling code now looks like this...
...and I changed the Function to...
Code:
Function OpenFile(sFile As String) As Long
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", sFile, "--stop-time 30 " & lstPlaylist.List(lstPlaylist.ListCount - 1), "C:\", SW_SHOWNORMAL)
End Function
...but get an "Object Required" error on the last line in the Function.
Re: Shell Execute with Commands...
So, I skipped the
and just used the code from the function, replacing sFile with "vlc" like so...
Code:
Dim Scr_hDC As Long
Scr_hDC = GetDesktopWindow()
StartDoc = ShellExecute(Scr_hDC, "Open", "vlc", "--stop-time 30 " & lstPlaylist.List(lstPlaylist.ListCount - 1), "C:\", SW_SHOWNORMAL)
Works like I need it to. Thanks for the heads up.
Re: [RESOLVED] Shell Execute with Commands...
Is your OpenFile function in the Form code module that has the lstPlaylist control? If not, then it won't be able to access the control (hence the Object Required error).
You can add another parameter to your OpenFile function and pass lstPlaylist.List(lstPlaylist.ListCount - 1) to that parameter, then change you ShellExecute call to use the parameter instead of accessing the lstPlaylist control directly.
PS: You are also passing the return value of ShellExecute to StartDoc - do you mean to pass it to OpenFile?