Solved

pass command line parameter in to a running program

Posted on 2011-09-14
9
369 Views
Last Modified: 2012-06-27
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
Comment
Question by:Matb396
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 5

Expert Comment

by:Rainverse
ID: 36536331
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 36536398
0
 
LVL 40
ID: 36536528
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:Matb396
ID: 36536756
James, how does this stop there being more then one instance of the program?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 36536838
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 36536939
>>how does this stop there being more then one instance of the program?

Have you checked my article?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 36537001
@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
 

Author Closing Comment

by:Matb396
ID: 36537010
Thanks

and emoreau that way it to complex
0
 
LVL 40
ID: 36537240
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MailAddress in vb 4 36
vb.net convert long time to mm:ss 23 22
"lblTime is not declared" 3 35
Import a excel sheet in a grid 2 13
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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