Friday, July 22, 2016

Can't open Excel when a file run from task scheduler

Why can't Excel open a file when run from task scheduler?

I wrote a powershell script that opens an excel workbook and runs a macro. When I run that script from PS console, or even from command line using powershell.exe script.ps1, it jus works. When I set up a task from the windows task scheduler, it raises an exception about that excel file, saying that it either does not exist or is already in use.

Solution 1

Create these two folders:

32Bit:

C:\Windows\System32\config\systemprofile\Desktop 

64Bit:

C:\Windows\SysWOW64\config\systemprofile\Desktop

Excel needs these folders if it's not run interactively.


Solution 2

Open Component Services (Start -> Run, type in dcomcnfg)

Drill down to Component Services -> Computers -> My Computer and click on DCOM Config

Right-click on Microsoft Excel Application and choose Properties

In the Identity tab select This User and enter the ID and password of an interactive user account (domain or local) and click Ok

Note: When setting DCOM permissions, if Microsoft Excel doesn't appear in dcomcnfg try mmc comexp.msc /32

No comments:

Post a Comment