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:
- 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.
- 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.
- 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.
- 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.