I wrote a script which outputs a text file as a log. I added a routine which allowed the log to be saved as Excel, when installed. The function worked fine when I ran it interactively, but crashed on the .SAVEAS routine on a 2008 R2 server as a scheduled task. I did some research on the web and found that this is a known issue. As you can see from the batch file below, the fix is to make sure that the systemprofile user has a Desktop folder. I wanted to ensure that even if someone ran a cleanup of profiles, it would not fail again.
@echo off
REM Creating this folder fixes Excel issues with scheduled task
REM It will fail if not running as administrator with UAC
if exist C:WindowsSysWOW64 GOTO X64
REM All one line
if not exist C:WindowsSystem32configsystemprofileDesktop. md C:WindowsSystem32configsystemprofileDesktop
GOTO RUNScript
:X64
REM All one line
if not exist C:WindowsSysWOW64configsystemprofileDesktop. md C:WindowsSysWOW64configsystemprofileDesktop
:RUNScript
cscript //nologo /b somescripthere.vbs
:END