Windows Scheduled Task Not Completing Successfully

JC34209324 51 Reputation points
2021-12-01T17:28:33.05+00:00

Hello, I have a Server 2016 Standard VM that has a windows scheduled task that runs a client application to pull files from a third party vendor to the server temporarily, then transfer the files to a network file share. This task has warnings and completes successfully nightly at 11 PM, but the files aren't being copied from the server to the file share. I've verified the task is running with the service account, the service account is a local administrator on the server, the task runs with the highest privileges, and the service account has read/write permissions on the file share.

If the scheduled task is ran manually, it completes successfully and the files are copied to the file share. This is the expected behavior.

I changed the directory of where the files would pull from the vendor and they make it to the server, but again, not to the file share. I also changed the time of the scheduled task, which was previously 12 AM, but the outcome persists. There's nothing else running on the server that I can see that would prevent the task from completing successfully.

The only thing I see in the task log are warnings that the task is already running. I've deleted both the scheduled task and client application, then re-installed and re-created them. This hasn't worked.

Is there anything else I should look into or I can attempt to resolve this?

154158-task-event.jpg154159-task-settings.jpg

Windows for business | Windows Server | User experience | Other
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. MotoX80 37,156 Reputation points
    2021-12-01T23:03:52.91+00:00

    Use the task manager and check to see if the client application is still running. If it is, kill it. Then check the status of the task to verify that it is not running.

    You can't guess as to what that program is doing. You have to implement logging of some kind. Hopefully that application is a command line program and not a GUI. You need to use a bat file to call it so that you can capture the stdout and stderr that the program generates.

    Create a bat file containing this (with the correct names and any command line arguments):

    @echo %date% %time% Script is starting.  
    C:\SomeAppFolder\YourApp.exe /someswitch=whatevertheappislookingfor   
    @echo %date% %time% Script is ending.  
    

    You might also want to add in a directory list command to verify that the network shares are visible to the account that the task executes as.

    Then in the task definition set it to execute program cmd.exe. In the arguments, point it to your bat file, and the log file+folder where you want to put them.

    /c c:\jobs\CallYourApp.bat 1>>c:\Logs\CallYourApp-%date:~10,4%-%date:~4,2%-%date:~7,2%.log 2>%1   
    

    This will create a daily log file for all executions of the task.

    It should look something like my cleanup task.

    154217-capture.jpg

    After the task runs, check the log file for errors and expected output.

    If the application is Windows forms app (GUI), then you have a problem. GUI programs do things like display message boxes with instructions to "click ok to continue". They were developed to interact with a human and not to run in unattended mode. If you have a GUI, you have to go back to whoever supports the app and ask them how you are expected to troubleshoot it when there is no way for any user to visually see it's window. Ask them if they can convert it to a console program.

    1 person found this answer helpful.

  2. MotoX80 37,156 Reputation points
    2021-12-02T03:35:11.07+00:00

    You are asking what I classify as a "Magic Crystal Ball Question". I don't know what the program is doing. You don't know what the program is doing. The only way to troubleshoot the issue is you need to get the program to tell us what error it encounters!

    If you are able to right click the task and select "run" and it works, but if you set the task to run at a given time and it fails, then possibly you've got something wrong with how you've configured how the task executes. Do you have the task set to run "only when the user is logged on"?

    You really need the application to create a log file so that you know what error it encounters. Otherwise you're just guessing.

    Update: You could also have a timing problem of some kind. Like a locked file. That is, when you manually ran the task, all of the shares were available and no other users were doing anything with the files that the program processes. But when the task ran at it's scheduled time, there was some other process that was doing something with the files and prevented the task's app from running.

    The bottom line is that you can't just guess what the problem is. You have to implement logging of some kind. The task scheduler can execute GUI programs, but they have to coded/executed in such a manner that they understand that they are running in unattended mode. They cannot use message boxes. There is no user to click on a button.

    How does the program know to start? A typical GUI shows a form where the user might type in a name, select a dropdown option, and then click on a button to start the requested operation. How does this program know what to do and when to start? Are you passing command line parameters? Have you checked the Application event log to see if the app writes entries there?

    1 person found this answer helpful.

  3. Limitless Technology 40,076 Reputation points
    2021-12-02T09:46:30.557+00:00

    Hi there,

    Before jumping into detailed troubleshooting, let's start with simpler one's. If the scheduled task works when you run it manually, but doesn't work automatically, take a closer look at its arguments.

    As it runs manually be sure to check if your conditions are properly configured.

    Check the scheduled task’s conditions , Some of the condition options such as the Start the task only if computer is on AC power. If that’s selected, the task isn’t going to run on laptops that aren’t plugged in.

    Also try giving this party tools a try as many users have recommended this.

    Hope this resolves your query.


    --If the reply is helpful, please Upvote and Accept it as an answer--


  4. MotoX80 37,156 Reputation points
    2021-12-03T19:09:40.26+00:00

    I changed the directory of where the files would pull from the vendor and they make it to the server, but again, not to the file share.

    I re-read your initial question. Is the above comment still true?

    If so, implement a .bat file with logging as I previously described. Add in additional statements to try and verify connectivity.

    @echo %date% %time% Script is starting.  
    @echo.Here is the local download directory.  
    @echo xxxxxxx > C:\SomeAppFolder\Downloads\Test-file-check-update-accesss.txt  
    dir C:\SomeAppFolder\Downloads\  
    del C:\SomeAppFolder\Downloads\Test-file-check-update-accesss.txt  
    @echo.Testing update access to network share.   
    @echo xxxxxxx > \\SomeServer\SomeShare\SomeFolder\Test-file-check-update-accesss.txt    
    dir \\SomeServer\SomeShare\SomeFolder\  
    del \\SomeServer\SomeShare\SomeFolder\Test-file-check-update-accesss.txt  
    @echo.Calling the application.   
    C:\SomeAppFolder\YourApp.exe /silent   
    @echo MyApp has finished. RC=%errorlevel%  
    @echo.Contents of local folder and network share.  
    dir C:\SomeAppFolder\Downloads\  
    dir \\SomeServer\SomeShare\SomeFolder\  
    @echo %date% %time% Script is ending.   
    

    Let the task run and then review the log. If YourApp.exe never completes, and the task still shows as running, then it's likely displaying a message box. You will have to talk to the vendor about that.

    If the bat file is able to display and update the folders, but the files still do not show up on the network share, Then download and run Process Monitor. Set a filter on "process name is yourapp.exe". Run the task and then check to see what file/folders the program accesses.

    https://learn.microsoft.com/en-us/sysinternals/downloads/procmon

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.