SettingsPath = Path.GetDirectoryName(Application.CommonAppDataPath) SettingsPath = Path.GetDirectoryName(Application.ExecutablePath) This.WindowState = FormWindowState.Minimized Private void Form1_Load(object sender, EventArgs e) Here is first part of Form1.cs: public Form1()
#Command line task scheduler code#
Here is code of Program.cs namespace EmailPaymentAdviceĪpplication.SetCompatibleTextRenderingDefault(false) Form1.cs does its thing, including logging as Why doesn't my C# application properly execute when it is run by the Windows task scheduler? It's a typical Winforms app. If I run batch file by double-click, I also see my program appear momentarily, and the desired logging takes place, so I know the program is properly running. I can see my program flash on the screen minimized, then leave, but no logging takes place. So scheduled task runs batch file, which runs my program with command-line switch. The scheduled task WILL run my application on demand, but application does not perform properly. The scheduled task WILL run Notepad on demand (so presumable also on schedule). Ok, I've had a chance do do further testing, and found: Is there any way to figure out why this application won't run when triggered by Windows scheduler? Thanks. I also tried explicitly building my application to target x86 platform. To force it to run with the 32-bit command line. The promising ones were %systemroot%\Syswow64\cmd.exe /C "c:\program files (x86)\Myprogram\Program.exe" This article, which offered several suggestions, none of which worked. If I manually double-click the batch file, it works properly, and the application runs and logs its actions. I put a logging statement at the beginning,Īnd it never gets any logging. When I run the task manually, I see the command window open, then close, but my actual application doesn't run. I tried changing the task to run a bat file instead, and put the command line in that. Whether I let it run on schedule (1:00 AM every day) or manually start the task, either way the application doesn't run even though the task history says the task properly ran.
#Command line task scheduler full#
The action contains the full path name of the application. I create the task, properties, action, etc. The issue comes when I try to schedule the job using the Windows Scheduler. I put code into the application so if it's run with a particular command-line argument, it runs minimized, clicks the appropriate "process" button, I have a Winforms application which my customer now wants to run regularly on a scheduled basis.