Task Scheduler not recognizing Onedrive.exe running

Bruno Hashimoto 5 Reputation points
2023-08-01T17:41:18.98+00:00

Hello eveyone, I hope someone would help me with my issues/questions.

Here is the scenario:

I have a VM that has a task set up in task scheduler and it checks a local folder which is synched with a sharepoint folder. The problem I'm facing is that the folder does not sync when the task is started by task scheduler (with the VM closed and user not logged in). When I run the task manually, it works.

The setup:

The task is set up to "Run whether user is logged on or not" and "Run with highest privileges" check box checked. The configured account/user (set up to run the task) has admin authorities.

VM that has the task scheduler set up runs a Windows Server 2016

Onedrive version Build 23.142.0709

Couple of things I notice (tests were done using the same account/user):

  1. When I logged into the VM, onedrive.exe starts automatically. Checking the task manager notice that onedrive.exe is running under the logged in user.
  2. When I run the task manually (user logged in) it works. Onedrive is automatically running and synced with sharepoint folder.
  3. When the task runs with VM closed (user not logged in), the task indicates that onedrive is not up and running and consequently sync do not happen.

With the above findings, I changed my script to start onedrive (when it is not running), by doing this, the task starts onedrive, and it syncs the folder as it should, but got a side effect... the onedrive icon does not show in the taskbar neither the sync icons aren't displayed in the folders/files (indicating its status) eventhough onedrive.exe is running. In this scenario I got a sync problem that the files got deleted from sharepoint folder (online) don't sync with the local folder. Checking the task manager, onedrive.exe is not running under the user.

So couple of questions:

  1. Why running the task thru task scheduler, onedrive does not come up nor is executing? as oppose to when I log in it automatically runs.
  2. How to make onedrive start under my user and has the onedrive icon displayed in the taskbar?

Attached is a screenprint where it indicates the onedrive running under the user and onedrive icon displayed in task bar (scenario that I want to happen when running the task thru task scheduler).

OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,110 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,055 questions
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,326 Reputation points
    2023-08-02T10:07:26.2333333+00:00

    Hello @Bruno Hashimoto,

    Thank you for your question and for reaching out with your question today.

    The behavior you are experiencing with OneDrive and Task Scheduler on a Windows Server 2016 VM might be related to how Windows handles user logon sessions and interactive sessions.

    When you log in to the VM interactively, your user session is considered an interactive session, and OneDrive is automatically started in that session. The OneDrive icon appears in the taskbar, and it syncs the folders as expected.

    However, when you run a task through Task Scheduler with the "Run whether user is logged on or not" option selected, the task is executed in a non-interactive session, which means it doesn't have access to the user's desktop or taskbar. As a result, OneDrive is not started automatically, and you might encounter synchronization issues.

    To address this, you can try the following steps:

    1. Configure OneDrive to Start with Windows: To ensure that OneDrive starts automatically even in non-interactive sessions, you can configure it to start with Windows. To do this, follow these steps: a. Log in to the VM interactively with the same user account that you use to run the task. b. Open the OneDrive settings by right-clicking on the OneDrive icon in the taskbar tray and selecting "Settings." c. In the Microsoft OneDrive settings window, go to the "Settings" tab, and check the box next to "Start OneDrive automatically when I sign in to Windows." d. Click "OK" to save the settings.
    2. Update Task Scheduler Action: In the Task Scheduler, edit the existing task or create a new one, and change the action to "Start a program." Set the program/script to the path of the OneDrive executable (usually "C:\Program Files (x86)\Microsoft OneDrive\OneDrive.exe"). Make sure to set the "Start in" field to the folder where OneDrive.exe is located.
    3. Set Up Delayed Start: In the "General" tab of the task properties, check the "Delay task for" option, and set a delay (e.g., 1 minute). This delay allows the task to start after the user logon session has been established, which might improve the chances of OneDrive starting successfully.
    4. Test the Task: Save the changes to the task and test it by running it through Task Scheduler. Verify if OneDrive starts and syncs the folders correctly.

    Please note that using Task Scheduler to run OneDrive in a non-interactive session might not fully replicate the behavior of OneDrive running in an interactive session. Some features, such as the taskbar icon and sync status, might not be available in non-interactive sessions.

    Additionally, consider the security implications of running tasks with user credentials. If your OneDrive setup involves sensitive data, ensure that the task's credentials are adequately protected.

    As a general recommendation, it is best to use OneDrive in interactive sessions to ensure the full user experience and sync functionality. Automated solutions might have limitations in non-interactive scenarios.

    I used AI provided by ChatGPT to formulate part of this response. I have verified that the information is accurate before sharing it with you.

    If the reply was helpful, please don’t forget to upvote and accept as answer.

    Best regards.


  2. 2024-08-30T11:49:31.6333333+00:00

    Hey Bruno,

    I'm currently facing the same problem as you did. Did you ever get a solution for that problem and could kindly share it with me if so?

    Thank you,
    Jonas :)

    0 comments No comments

Your answer

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