Page 1 of 1

How to receive command lines in your Application! Rate Topic: -----

#1 Jack Eagles1  Icon User is offline

  • Pugnacious Penguin (inspired by no2pencil)
  • member icon

Reputation: 183
  • View blog
  • Posts: 1,152
  • Joined: 10-December 08

Posted 29 January 2012 - 05:38 AM

Hey Guys,


I've noticed that nobody's posted a tutorial in the .NET section on how to receive command lines in a program. This is a relatively simple thing to do, and can yield great results. For those who don't know what command lines are, i'll explain.
When you execute a program, you add certain parameters called command lines. If anyone's ever worked with CMD using any command such as "ipconfing /release", "/release" is the command line, and tells the "ipconfig" executable what you want to do with it.

In this tutorial, we'll be using command lines in order to start a program minimized. Firstly, open Visual Studio 2010 (or Visual Basic 2010 depending on your installation), and create a new project.

Then, when the designer for Form1 is visible, double click form one, and go to the Form1_Load event. Add this code:

        If Environment.GetCommandLineArgs.Count <> 1 Then
            If Environment.GetCommandLineArgs(1) = "/minimized" Then
              Me.WindowState = FormWindowState.Minimized
            End If
        End If




What the code above does is to check how many command lines have been sent to the program - if there's only one (which is the when launching any program), then we ignore it. Otherwise, we select the first Command Line that has been sent to the program and see if it is "/minimized". If so, we set the program's windowstate to minimized.


Now, to test this, create a new shortcut to your program. I've created an animated gif to show you how to do it:
Posted Image


Hopefully you guys will enjoy this tutorial and get something out of it. Please don't hesitate to ask me questions about it (although I'm not online every day anymore).

It should be very simple to adapt the code above to your needs - such as being able to open files with Command lines.

This post has been edited by Jack Eagles1: 30 January 2012 - 03:03 PM


Is This A Good Question/Topic? 2
  • +

Replies To: How to receive command lines in your Application!

#2 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,508
  • Joined: 16-March 11

Posted 31 January 2012 - 09:03 PM

Excellent, should be very helpful for many.
Was This Post Helpful? 0
  • +
  • -

#3 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Posted 30 March 2012 - 02:57 PM

Very good sir.
Was This Post Helpful? 0
  • +
  • -

#4 Darkish  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-October 12

Posted 18 October 2012 - 09:54 PM

Thanks for this nice tutorial
Was This Post Helpful? 0
  • +
  • -

#5 blaboom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-October 12

Posted 29 October 2012 - 03:27 PM

Very nice! Just what i was looking for!

Thank you!

Is it possible to know from where (folder) the program was opened?

I'll explain:

When someone right click on a .mp3 file will have the option to play it or add to a playlist etc, but how can we know where is the folder of that file?

In my case, i would like to open a program via folder right click and know from wich folder i've done it to use that path in my program.

Already know how to add the program to folder's right click context menu, but i need to know in wich folder it was opened.

I'm searching for the solution yet but i don't know what to search because it's a little bit confusing i guess.

Thanks in advanced.

Again, great tutorial! Congratulations.
Was This Post Helpful? 0
  • +
  • -

#6 blaboom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 29-October 12

Posted 29 October 2012 - 03:57 PM

Update:

I have almost solved the problem with this:

Dim x As String = Environment.CurrentDirectory
        MsgBox(x)


If i go here "C:\MyUser\"

and have a folder named "MyFolder" there and if i right click in that folder i will get the "C:\MyUser" path

What i need it's the "MyFolder" path like this "C:\MyUser\MyFolder" to be used with my program.

Any ideias in how to get it?

Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1