Hack Forums
[.NET] [TUT] Passing Arguments To A Console Application - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [TUT] Passing Arguments To A Console Application (/showthread.php?tid=488166)



[TUT] Passing Arguments To A Console Application - ubbelol - Jun 18, 2010

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..


* - Apple - Jun 18, 2010

Nice tutorial, good job. I think this will be good with RAT's.


* - ubbelol - Jun 18, 2010

Ty Cloak :p Hopefully i get some more feedback. :c


* - Bitwin - Jun 18, 2010

Nice tutorial, good explanation.
Copy and paste time!! No, just kidding 😝


* - ubbelol - Jun 18, 2010

(Jun 18, 2010 04:34 AM)C00k13 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.


* - Romeo. - Jun 18, 2010

Might came handy some day.

Thanks !


* - Bitwin - Jun 18, 2010

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