Solved

Pass command-line arguments to already running application

Posted on 2010-08-24
3
334 Views
Last Modified: 2012-05-10
I know how to parse through the command line arguments passed to the application when it was originally opened. Is it possible to pass more arguments to the application after it has already been opened? The app I am running is a single instance application and I was hoping to be able to pass them in the MyApplication_StartupNextInstance subroutine but can't seem to grab the new command-line parameters. Thanks.
0
Comment
Question by:rbichon
  • 2
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Sure....you're using "e.CommandLine" in the StartupNextInstance() event right?
Namespace My



    ' The following events are available for MyApplication:

    ' 

    ' Startup: Raised when the application starts, before the startup form is created.

    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.

    ' UnhandledException: Raised if the application encounters an unhandled exception.

    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 

    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.

    Partial Friend Class MyApplication



        Private Sub MyApplication_StartupNextInstance(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupNextInstanceEventArgs) Handles Me.StartupNextInstance

            Dim args As New List(Of String)

            args.AddRange(e.CommandLine.ToArray())



            ' ... use "args" somehow ...



        End Sub



    End Class





End Namespace

Open in new window

0
 
LVL 1

Author Comment

by:rbichon
Comment Utility
Nope. That was it! Thanks!!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
*Just FYI, "Environment.CommandLine" ALWAYS gets the args from when the process was STARTED:
http://msdn.microsoft.com/en-us/library/system.environment.commandline.aspx

    "This property provides access to the program name and any arguments specified on the command line when the current process was started."
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now