[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

pass command line parameter in to a running program

Hi All

Ive used command line parameter to get my vb.net to open in to a section of the program, however im finding that it reopens the program and cause the program to be running mutable times how do i get it so that the command line parameter is executed without reopening the program again.

In other words how would i pass command line parameter in to a running program?

Cheers

matt
0
Matb396
Asked:
Matb396
  • 2
  • 2
  • 2
  • +2
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
Jacques Bourgeois (James Burger)Commented:
The command line string includes the name call to the program, as shown by the following, where the parameter is VS.

"C:\Program Files\Prog\Projects\JBFlow\bin\JBFlow.exe" VS

If you  use it as such, you are simply relaunching the application.

You need to isolate the second part of the command line. In order to do it, I usually use the Split method of the String class, splitting on double quote followed by a space, which are the 2 caracters just before the parameter:
Dim commandLineArgs() As String = Environment.CommandLine.Split({""" "}, StringSplitOptions.None)

Open in new window

This gives me an array of  1 String if there is no paramater, an array of 2 Strings if there is one. So I have to check if there really is a second one:
If commandLineArgs.Length > 1 AndAlso commandLineArgs(1).Length > 0 Then 'Got a command line argument
  myArgument = commandLineArgs(1)  'VS
Else
  'There is no command line argument
End If

Open in new window

0
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!

 
Matb396Author Commented:
James, how does this stop there being more then one instance of the program?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
This uses the StartupNextInstance() event which fires when the "Enable Single Instance" box is checked in Project --> Properties:
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_24297753.html

See "Overview of the Visual Basic Application Model":
http://msdn.microsoft.com/en-us/library/w3xx6ewx(VS.80).aspx
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>how does this stop there being more then one instance of the program?

Have you checked my article?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
@Emoreau,

You should update that article to also show how to use the default WindowsFormsApplicationBase class provided when you click on the "View Application Events" button...
0
 
Matb396Author Commented:
Thanks

and emoreau that way it to complex
0
 
Jacques Bourgeois (James Burger)Commented:
James, how does this stop there being more then one instance of the program?

You are not reusing the whole command line, you have isolated only the parameter.
0

Featured Post

Technology Partners: 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!

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now