Solved

Pass command-line arguments to already running application

Posted on 2010-08-24
3
350 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
ID: 33515740
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
ID: 33515761
Nope. That was it! Thanks!!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 33515769
*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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

861 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

30 Experts available now in Live!

Get 1:1 Help Now