Task scheduler cannot open batch file when set to run whether user is logged on or not

I have resolved this problem with help from a contractor who was doing some other work for my institution.

In the properties window for the task, on the Action tab, when creating or editing the action that opens the batch file (in my case test.bat), there is the "Program/script:" field and there is also a "Start in (optional):" field. I previously had the "Program/script:" field containing the full path to the file, ending with the file name, and I had the "Start in (optional):" field null. This configuration appears to work without issue when the task is set to "Run only when user is logged on" in the General tab of the task's properties window. However, this configuration does not work when the task is set to "Run whether user is logged on or not".

In order to resolve the problem, I changed the action so that the "Program/script:" field contained only the file name, not the file path. I put the file path in the "Start in (optional):" field. This configuration works when the task is set to "Run only when user is logged on"! I have tested with the task running on a trigger and also with running it manually.


Not sure if this helps. My issue was using a interactive program (in particular Excel) as well.

Creating the 2 empty folders (Desktop) solved it. Create both even if you are running on x64.

C:\Windows\System32\config\systemprofile\Desktop
C:\Windows\SysWOW64\config\systemprofile\Desktop

I debugged my code and realised the code exited at this line

ExcelFile excelFile = new ExcelFile(directory, filename);

I read this solution somewhere and I cannot find the URL now.