0

I am working on console application (.NetFramework 4.8 in VS2022) for Process Some data.

I want Send parameter when execute .exe file from Scheduler and manually with different parameters.

its working in VS2022 LOCAL PC with Release and Debug Mode, **But **when I publish application and execute by double click or from scheduler parameter not passing to .exe file.

let me know if any Configuration missing or other way to Identify .exe file execute from scheduler or manually, in console Application Code.

Thanks.

I tried with VS2022 and VS2019 with .net framework 4.5 and 4.8, also tried to identification using Environment.CurrentDirectory but its not working properly.

public static void Main(string[] args)
{
   try
   {
       Console.WriteLine($"Process Start");

       if (args.Length > 0)
       {
           Console.WriteLine($"you passed argument {args[0]}"); // this argument value not working when Application Published
           if (args.Any(X => X == "manually")) {
               // execute from manually process
           }
           else {
               // execute from scheduler process
           }
       }
   }
   catch (Exception ex)
   {
       Console.WriteLine(ex.Message);
   }
   Console.WriteLine($"Process End");
   Console.ReadKey();
}
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • What would you expect to happen or see? You probably do not pass any args when double clicking? – Fildor Jan 11 '23 at 14:51
  • By "scheduler" you mean Windows Task Scheduler? – Fildor Jan 11 '23 at 14:52
  • BTW: It's probably not too good an idea to include a `Console.ReadKey()` when the app is planned to be used in a scheduler. – Fildor Jan 11 '23 at 14:54
  • Yes, its Windows Task Scheduler. Console.ReadKey() is use for showing output while development time @Fildor – Parin Patel Jan 11 '23 at 14:54
  • So if you pass _no_ args ( 0 ) , then `Console.WriteLine($"you passed argument {args[0]}")` is going to throw IndexOutOfRangeException. Does it? => https://dotnetfiddle.net/ZQNjKN – Fildor Jan 11 '23 at 14:58
  • If you configure the scheduler to start the App under "Service" Principal or specific User, you could use that to determine if you are running scheduled or manually. => https://stackoverflow.com/q/1240373/982149 If the scheduler runs it as current User, that won't work, of course. – Fildor Jan 11 '23 at 15:03
  • @Fildor thanks a lot for helping, finally I got solution and posted below. – Parin Patel Jan 11 '23 at 16:07

1 Answers1

0

Finally I got solution on above question go to > Property > Publish > Options under the Install Mode and Settings > Select Manifest > Checked Allow URL parameters to be Passed to application.

enter image description here