I have done some extensive searching over the net however I cannot seem to find a concrete solution to the problem I am facing. The closest was this article ... but still no solution :( scheduled task run .exe problem
Basically the environment is a Windows Server 2008 R2 running a C# console application. When I run the console application manually a text file (using NLog) is created and appended, however when I run the console from windows scheduler using the Domain Administrator account, the application runs (as I deciphered from Event Viewer logs) but the text file is not created / appended. I also tried changing the account that runs the scheduled task (from Domain Administrator to Local Administrator account) but the problem is still persisting.
Cannot think of anything else I can do. Any fresh ideas are appreciated :)
Fix 1. Press Windows + R, type msc in Run box, and press Enter to open Windows Services. Scroll down in Services window to find Task Scheduler. Right-click Task Scheduler and choose Properties. In Task Scheduler Properties window, you can set the Startup type as Automatic.
If it's a scheduled task that the non-admin user account has created, he/she can disable it, if it's a scheduled task created by an administrator he/she will need modify permissions to be able to enable/disable scheduled tasks in the Task Scheduler, and that requires administrator rights.
thought id post as an answer as it's easier to put the code in:
make sure you specify the full path to the NLog:
string filepath = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),"NLog.txt");
when running as a scheduled task the working directory of your application can be different, such as running under system means the working directory is C:\Windows\System32.
this could be your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With