Windows server 2012 scheduled tasks run using default profile ( when ran session less ) even if specific account is specified

Solution 1:

I reported this bug to Microsoft last year, via our 3rd party support company. They acknowledged it as a bug, but refused to fix without a high business impact - I was hacking something in development at the time.

In my research I discovered that the correct profile will be used if you have an interactive session running as the user your scheduled task is set to run as. Microsoft suggested a workaround of running calc.exe (or some other process) prior to the scheduled task that you actually want to run. This appears to work in my case.

I've hit the bug again with a new development, so I've asked our support company to raise it with Microsoft again and referenced this post to show that other folks are hitting the issue.

Solution 2:

You can either start another interactive task a minute or two before your task, which will give Windows time to load the correct profile, or launch the task via a batch file.

set "USERPROFILE=%USERPROFILE%\..\%USERNAME%"
set "APPDATA=%USERPROFILE%\AppData\Roaming"
set "LOCALAPPDATA=%USERPROFILE%\AppData\Local"
"%~dp0\YOUREXEHERE.exe"

Copy this into a batch file, and put it in the same directory as the exe you want to run. Then change the YOUREXEHERE to the name of the EXE. Do not change anything else in the script and save.

Then run the batch as your scheduled task instead of the EXE. Whatever user runs the task, the application will use their profile.