Application is working fine when runned manually, but when is running from task it doesn't

José Johnen 1 Reputation point

Hello there,

That's it basically, when i run the app manually is able to find the files than it supposed to look for and work with them as it should, but when running from the task scheduler, even with my user, although the application run it's unable to find the files to start processing them.

The application is a minimal API done in .Net 6, the server is a Windows Server 2008 R2 Enterprise SP1 Build 7601.

Can somebody tell me what can be stopping the app of finding the files to process them when running from a task?

Or at least how can i fix it?

The expected behaviour is than the app find such files when running from a task and process them, the task is already running even if the user is logged or not, and with the highest administrative priviledges.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
9,470 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 25,656 Reputation points

    Once common issue is that network drives that are mapped as part of your desktop logon are not mapped in a scheduled task environment. If your program is referencing a drive letter, change that to use a UNC path. \ServerName\ShareName

    Beyond that, forum users would have no idea what your program is doing. In an un-attended environment like a scheduled task, you need to implement logging of some kind so that when an error occurs, something is written to the log.

    If you are executing a command line program, then capturing stdout and stderr might be sufficient.
    Create a bat file that executes your program. Echo %date% %time% as the first and last line the .bat so that know when the task starts and ends.

    @echo %date% - %time% MyScript is starting.
    @echo %date% - %time% MyScript is ending. SomeProgram RC=%errorlevel%  

    Then change the scheduled task to execute program "cmd.exe".

    In the arguments field set it like this example:

    /c C:\Scripts\MyScript.bat  1>>"C:\Scripts\Logs\MyScript-%date:~10,4%-%date:~4,2%%date:~7,2%.log" 2>&1

    That will create a daily log file of all executions of the task. That will capture stdout and stderr for programs that get called.

    0 comments No comments