Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Server 2008 R2 not writing to text file from task scheduler

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 :)

like image 801
tech-dev Avatar asked Sep 24 '13 09:09

tech-dev


People also ask

Why is my Windows Task Scheduler not working?

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.

Do you need admin rights to run Task Scheduler?

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.


1 Answers

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.

like image 108
SmithMart Avatar answered Nov 15 '22 04:11

SmithMart