Results 1 to 8 of 8

Thread: [2008] Open with multiple arguments

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    [2008] Open with multiple arguments

    Hi!!

    If you select many MP3 files and press enter, and the default program to open the MP3 files is windows media player. It opens windows media player with all the files in the playlist "Now Playing".

    How can I do so that my program acts the same, but just adds the filenames to a Listbox?

    I have this code but it doesnt work, well works but just for a single file:
    vb.net Code:
    1. Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    2.         If My.Application.CommandLineArgs.Count > 0 Then
    3.             For a As Integer = 0 To My.Application.CommandLineArgs.Count - 1
    4.                 Dim FI As New IO.FileInfo(My.Application.CommandLineArgs(a))
    5.                 If FI.Extension.ToUpper = ".MP3" Then
    6.                    Listbox1.Items.Add(IO.Path.GetFileNameWithoutExtension(My.Application.CommandLineArgs(a)))
    7.                 End If
    8.             Next
    9.         End If
    10.     End Sub
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2008] Open with multiple arguments

    Not sure why that doesn't work. Did you debug to see what the arguments actually are?
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  3. #3
    Junior Member
    Join Date
    Oct 2008
    Posts
    31

    Re: [2008] Open with multiple arguments

    I tested your code on my compiler (VB 2005 expressed) and it seamed to work as expected. Double check what command line arguments are being passed by the calling application. In order for the code to work properly the arguments should be space seperated.

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2008] Open with multiple arguments

    in 2008 i did this
    Code:
            If My.Application.CommandLineArgs.Count > 0 Then
                For cla As Integer = 0 To My.Application.CommandLineArgs.Count - 1
                    Debug.WriteLine(My.Application.CommandLineArgs.Item(cla))
                Next
            End If
    worked as expected.

    i did find that i had an error trying to access the command line arguments with:
    Enable ClickOnce Security - Checked
    This is a Full Trust Application - Selected.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2008] Open with multiple arguments

    Well it works but opens me a lot of instances of my program, with a file in the listbox in each program, instead of one and only instance with all the files in the listbox. I've try to make it a single instance application and still only adds a file to the listbox.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  6. #6
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [2008] Open with multiple arguments

    You have probably set the file attributes wrongly. I cannot help you how to set them properly, but it seems to me that windows now sees the file as being opened only once at a time. So what it does is open a new instance of your application for each selected file.

    The same happens for example with Notepad: try creating a few .txt files with notepad on your desktop, select them all and press Enter. All the files are opened in a separate instance of Notepad.

    What you want is that windows opens only one instance of your app with the selected files as separate commandline args.

    So this is certainly an error in the way windows handles the opening of multiple files, not in the way your application handles the commandline args.

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: [2008] Open with multiple arguments

    Quote Originally Posted by Lasering
    If you select many MP3 files and press enter, and the default program to open the MP3 files is windows media player. It opens windows media player with all the files in the playlist "Now Playing".
    I understand the problem now! What you're trying to do won't work with traditional command line arguments as each time a file is opened Explorer goes to the specified application and passes the path of the file into it.

    So in your current application you'll get a ton of instances.

    So if you want your current code to work you have to highlight all of your MP3s and drag them onto your executable / shortcut or add each path of each MP3 manually to either the command line or run box for your application.

    If you want your application to work like Windows Media Player then you'll need to setup a single instance application. In VB2005 / VS2008 there is a checkbox somewhere in your project's properties that says "make single instance" or something to that effect. Then everytime a new instance of your application attempts to open, instead, you'll have an event thrown with the appropriate command line arguments so you can keep adding things to your listbox.
    Quote Originally Posted by NickThissen
    So this is certainly an error in the way windows handles the opening of multiple files, not in the way your application handles the commandline args.
    It has nothing to do with the way Windows handles opening multiple files. Windows doesn't do that. This has to do with what the OP's application is doing when Windows sends commands to it.
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  8. #8

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2008] Open with multiple arguments

    Quote Originally Posted by kasracer
    Then everytime a new instance of your application attempts to open, instead, you'll have an event thrown with the appropriate command line arguments so you can keep adding things to your listbox.
    I've already checked the make single instance option.
    Which event do I have to check now?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

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