I have a windows script (vbs) file that uses Microsoft Excel (2010)'s API to create excel files.

Today I needed to migrate the script to a new server running Windows Server 2008 R2.

When I run the script manually it runs perfectly.

When I try to run the same script as a scheduled task, with the same user (who is an administrator on the machine in question), and 'run with highest privileges' checked, it can run up to a point, but fails when it tries to use Excel's api to save a file.

Specifically the script never goes past the wb.saveas...

logfile.writeline ("About to save c:\scripts\" & agentfilename & ".xls")
wb.saveas "c:\scripts\" & agentfilename & ".xls", 56
logfile.writeline (result & " Saved c:\scripts\" & agentfilename & ".xls")

(My log file contains the 'about to save' entry, but not the 'saved' entry.

Note, 'wb' is created earlier in the script as follows - set wb = xl.workbooks.add One problem here is that I cannot see what error is occuring because the script is being run as a scheduled task.

This ran perfectly on the previous server (Server 2003).

I have UAC turned off completely on the new server.

The script has write access to the folder because it is able to create and append to the log file.

Any ideas?

Edit:

I found out what the problem is.

Apparently the scheduled task can only work if the 'run only when the user is logged in' radio button is checked, because Excel hangs at attempts to save the file if the user is not logged in. Odd that I didn't have this problem on the old server (same copy of excel, uninstalled from the old server and installed on the new)

This is a pain because it means I will need to leave the user logged into the machine for this scheduled task to work. If anyone knows of a way around this limitation I would be greatful.

有帮助吗?

解决方案

I found out what the problem is.

Apparently the scheduled task can only work if the 'run only when the user is logged in' radio button is checked, because Excel hangs at attempts to save the file if the user is not logged in.

This is a pain because it means I will need to leave the user logged into the machine for this scheduled task to work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top