Share via

Task scheduler - does not work with the option 'Run whether user is logged on or not.'

Anonymous
2024-02-06T15:46:56+00:00

I have a problem with the task scheduler running on 'Microsoft Windows Server 2019 Datacenter'. I tried to configure a task scheduler to run a batch file to copy a file from a folder (Azure file share folder mounted on the server) to another folder (present in the server). I'm using local admin account to login and schedule the task. The Batch file as administrator rights.

When I run the batch file manually, it works fine. The task scheduler runs fine with the option 'Run only when user is logged on'. But it fails to execute the batch file with the option 'Run whether user is logged on or not.'

When the task scheduler runs with the option 'Run whether user is logged on or not, it shows that the task finished successfully.

Schedular Log -

Task Scheduler successfully finished "{aacb1a31-c097-408e-8d46-c380ce95d7e8}" instance of the "\TEST-AUTOMATION" task for user "AZ-PSMB24\sysadmin".

Windows for business | Windows Server | User experience | Remote desktop services and terminal services

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

32 answers

Sort by: Most helpful
  1. Anonymous
    2024-08-06T18:26:30+00:00

    I found this solution on stackoverflow that worked for me.

    In the properties window for the task, on the Action tab, when creating or editing the action that opens the batch file, 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 with full path to the directory where the batch file is located.
    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 whether user is logged on or not"! 
    Also, my batch file name does not have any spaces.

    Was this answer helpful?

    3 people found this answer helpful.
    0 comments No comments
  2. Anonymous
    2024-09-18T05:18:22+00:00

    For me is still not working.

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments
  3. Anonymous
    2024-05-23T18:22:25+00:00

    The issue you're encountering with the Task Scheduler is commonly related to permissions and the environment context in which the task is run. When you select "Run whether user is logged on or not," the task runs in a non-interactive session, which can cause issues with network resources and mapped drives, such as your Azure file share. Here are some steps to resolve this:

    1. Use UNC Paths: Instead of using a mapped drive letter (e.g., Z:), use the full UNC path (e.g., \servername\sharename). Mapped drives are user-specific and might not be available in a non-interactive session.
       batchCopy codexcopy \\AzureFileShare\folder\file.txt C:\DestinationFolder\
      
    2. Network Credentials: Ensure that the task is configured to use the correct network credentials to access the Azure file share. You might need to include a net use command to map the network drive within the script itself.
       batchCopy codenet use \\AzureFileShare\folder /user:AzureUser AzurePassword
       xcopy \\AzureFileShare\folder\file.txt C:\DestinationFolder\
       net use \\AzureFileShare\folder /delete
      
    3. Task Configuration: Double-check the following settings in the Task Scheduler:
      • Run with highest privileges: Ensure this option is checked.
      • Use a local account with administrative privileges: Confirm that the account has the necessary permissions to access both the source and destination paths.
    4. Interactive Services Detection: Verify that there are no prompts or UI elements that might be blocking the task when run in a non-interactive session. Since the session is non-interactive, any such prompts will not be visible or actionable.
    5. Task Scheduler Log: Review the Task Scheduler log for any errors or warnings that might give more insight into why the task did not perform as expected, despite reporting success.
    6. Environment Variables: Ensure that any environment variables or dependencies required by the batch file are accessible in the system context.

    Implementing these steps should help address the issue with the Task Scheduler not executing the batch file correctly when set to "Run whether user is logged on or not."

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  4. Anonymous
    2024-05-13T06:03:48+00:00

    In my case I cannot run even with local user account with task option "Run whether user is logged on or not"

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  5. Anonymous
    2024-03-14T09:21:27+00:00

    Hi Shan,

    the problem definitely is with the task scheduler application. We have the same issue with a couple of computers. If you run with the same account without a task scheduler or if you choose "Run only when user is logged on it works. But if you save the credentials of the same user and choose "Run whether user is logged on or not" it's not working.
    We need to investigate this.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments