Passing flags to program via ShellExecute

Posted on 2004-11-28
Medium Priority
Last Modified: 2008-03-17
I am writing a program to manage my mp3 playlists, i have currently got it to open a playlist for an album - although i can only open 1 album at a time. I would like to pass the option to enqueue files aswell as opening one set at a time. Looking at the winamp exe i need to call [winamp.exe] /ADD [file name for playlist].

i currently use
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

this function like this....

ShellExecute 0, "Open", sPlaylists.Item(List1.ListIndex + 1), "", "", SW_SHOW

but i would also like to pass the "/ADD" flag to append to the playlist.

Question by:scanadmin
LVL 55

Accepted Solution

Jaime Olivares earned 1500 total points
ID: 12690168
I suggest you to use WinExec instead:

Declare Function WinExec Lib "kernel32" Alias "WinExec" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long

WinExec("your command and arguments and flags here", 1)

Don't forget to give correct exe's full path

Author Comment

ID: 12690210
thanks for your fast reply,

is there no way to do it without the full path as with shellexecute. i am planning to make the application and distribute it over the web so out like it to run with the default players.

LVL 32

Expert Comment

ID: 12690287
If the default player is not winamp, then do you still want to pass the /ADD switch?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 55

Expert Comment

by:Jaime Olivares
ID: 12690519
If you want to pass multiple files or some switches, then you have to call application by its name, including path, with exception of applications that are in windows folder or in current active folder. But there are many alternatives to obtain application full path by reading the Windows Registry.
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12690535
Also read last section of this page (Controlling WinAMP from Visual Basic):
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 12690892
Try this
              ShellExecute 0, "Open", sPlaylists.Item(List1.ListIndex + 1), "/ADD", "", SW_SHOW



Author Comment

ID: 12726299
cheerz surju.... i have tried that, doesnt seem to work!

jamie, willl try the registry thing - seems like the best option

thanks for all your help.

Author Comment

ID: 12726578
for those of you who are interested i solved the problem like this

Dim sCommand As String
sCommand = ReadRegistry(HKEY_CLASSES_ROOT, "Applications\Winamp.exe\shell\Enqueue\command", "")
sCommand = Replace(sCommand, "%1", sPlaylists.Item(List1.ListIndex + 1))
WinExec sCommand, SW_SHOW


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question