Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[TUT] Passing Arguments To A Console Application

Hey, i've had a few requests on making a tutorial on how to pass arguments on a VB.NET/C# console application so here we go:

It's actually ALOT more simple than it might sound, all you have to do is creating an string array that splits the arguments inputted.

Alright so here's the full code:

Code
Sub Main()
  Dim strArray() As String = Command.Split("-")
  If Not strArray.Length < 1 Then
    For i = 0 To strArray.Length - 1
    Console.WriteLine(strArray(i).Trim())
    Next
  End If
  Console.ReadLine()
    End Sub

Now lets break it down into lines

The first line:
Code
Dim strArray() As String = Command.Split("-")

What that does is basically split the input that users type in by the char "-". You can change the char to whatever you want your args to be splitted with, example if you use "/" as a split char you enter args like:

Code
C:\path.exe /arg1 /arg2 /arg3

The second line:
Code
If Not strArray.Length < 1 Then

This simply tells the program to only execute the following code IF the strArray length (amouns of args inputted) is not less 1.

On to third:
Code
For i = 0 To strArray.Length - 1

Here we create a loop wich goes from 0 to the length of strArrays length (amouns of args inputted) and for each argument we execute the following code:

Code
Console.WriteLine(strArray(i).Trim())

This outputs the current argument in strArray, strArray(0) would be "arg1" and strArray(1) would be "arg2" etc, i think you get the point.

The Trim() command removes any spaces in the start and end of the current argument so you won't get arguments like " arg1 " wich can be hard to use later on in the program.

And the last
Code
Console.ReadLine

Simply waits for the user to input anything, this is just to pause the window and not making it close instantly.

Heres a little video example of the console in action:

[IMG]http://i350.photobucket.com/albums/q408/ubbe12/tut1-13.gif[/IMG]

WTB Feedback. Sorry for my lame english..
Probably coding some useless shit.
Nice tutorial, good job. I think this will be good with RAT's.
Ty Cloak :p Hopefully i get some more feedback. :c
Probably coding some useless shit.
Nice tutorial, good explanation.
Copy and paste time!! No, just kidding 😝
(Jun 18, 2010 04:34 AM)Bitwin Wrote:  Nice tutorial, good explanation.
Copy and paste time!! No, just kidding 😝

Lol :p Thanks for the feedback, i was kinda expecting flame when i saw you posted. 😁 Atleast you're mature, that's good.
Probably coding some useless shit.
Might came handy some day.

Thanks !
Haha, I thought first, but what can I possible flame in this thread ? 😁
Also, there is no point :P


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by ivankirevichMar 4, 2023 11:22 AM 6 247 Mar 4, 2023 11:22 AM
Last Post: ivankirevich
[C] by Gliese 667CcAug 28, 2021 11:08 AM 3 192 Aug 28, 2021 11:08 AM
Last Post: Sierra-117
[.NET] by VUEDUEJul 11, 2021 06:45 AM 4 209 Jul 11, 2021 06:45 AM
Last Post: VUEDUE