Starting EXE with args

NachitoMax 411 Reputation points


I need to start an EXE with args that will run some validation as it starts. I sort of understand the Process.Start(args) but not sure if its this that i need.

I need to to know 2 things

  1. how to call the exe correctly with the args
  2. where in the exe do i put the code to receive the args

The validation is basically do not run if you dont receive the correct args as it needs to be called by a 3rd party application in order to work.


Microsoft Technologies based on the .NET software framework.
3,533 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,137 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sam of Simple Samples 5,516 Reputation points

    See Process.Start Method. Part of one of the examples is:

    Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");  

    In that, C:\\myPath\\myFile.htm is the arguments.

    See Main() and command-line arguments. Try out that sample program. In Visual Studio you can specify some arguments to use for testing purposes by going to the project's properties then go to Debug and in Start options is Command line arguments. So you can put some sample arguments there and see what they look like in execution. Then you can modify that program to do whatever processing you need and when it works you have sample code ready for use.

    0 comments No comments

  2. Bruce ( 59,131 Reputation points

    more detail:

    typical spawn:

    Process.Start("myapp.exe", "-l foo1.txt foo2.txt");  

    .net 6 my app

    var log = false;  
    var fileNames = new List<string>();  
    foreach (var arg in args)  
        if (arg == "-l")   
            log = true;  
    Console.WriteLine($@"log={log} fileNames={string.Join(",",fileNames)}");  

    note: like unix utilities arg[0] is not the executable name

    0 comments No comments