Search code examples
c#parameterswindows-explorer

Pass variable to a .exe file from windows explorer


I have made a simple project in c#. To execute this program you have to pass it a string.

static void Main(string[] args)
{
    DateTime? dtDebut = null;
    if (args.Length > 0)
       dtDebut = DateTime.Parse(args[0]);

    DateTime? dtFin = null;
    if (args.Length > 1)
       dtFin = DateTime.Parse(args[1]);

    bool bGetDateFromTable = true;
    if (args.Length > 2)
       bGetDateFromTable = Boolean.Parse(args[2]);


    ObjetAXION objetAXION = recupererAxion();

    DateTime date1 = DateTime.Now;
    AXION.OLENotes.ScanFiles(objetAXION, dtDebut, dtFin, bGetDateFromTable);
    DateTime date2 = DateTime.Now;
    Console.WriteLine("Temps du scan: " + (date2 - date1));
}

But how can I run the .exe file with a parameter from windows explorer ?

EDIT :

I will 100 % pass a date.


Solution

  • Create a shortcut to your program. Edit the target of the shortcut (in the properties window of the shortcut) to include command line arguments.