Results 1 to 5 of 5

Thread: [RESOLVED] Shell Execute with Commands...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    127

    Resolved [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.
    Code:
    OpenFile "vlc"
    My question is: How can I load vlc with the commands/parameters?

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,891

    Re: Shell Execute with Commands...

    Pass the parameters to the lpParameters parameter. Right now you are passing an empty string for the parameters.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    127

    Re: Shell Execute with Commands...

    My calling code now looks like this...
    Code:
    OpenFile "vlc"
    ...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.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2013
    Posts
    127

    Re: Shell Execute with Commands...

    So, I skipped the
    Code:
    OpenFile "vlc"
    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.

  5. #5
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,891

    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?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width