Create a shortcut to your program. Edit the target of the shortcut (in the properties window of the shortcut) to include command line arguments.
Pass variable to a .exe file from windows explorer
-
30-06-2022 - |
Question
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
OTHER TIPS
Create a Windows batch (text file with *.bat extension) and specify the call in there:
MyProg.exe MyFirstArgument MySecondArgument
That's it. See this for further info.
Open Regedit, find Computer\HKEY_CLASSES_ROOT\Folder
You will find shell\open\command
there with the defaultentry %SystemRoot%\Explorer.exe
<-- This is an good example, you can pass arguments there.
Copy Folder
and rewrite it to your needs.
Another example is
- "C:\Users\youruser\AppData\Local\Google\Chrome\Application\chrome.exe" -- "%1"
You can pass arguments using "", %1 is the file.
BTW: This is not a Stackoverflow-able question.