Asked by:
Opening Excel Workbook Fails when run from Scheduled Task on Windows Server 2008 Rw

Question
-
Hi,
I have a little vbs script that instantiates the Excel.Application object and then opens a work book to perform some tasks on it. The script runs fine when run from the command line. When I attempt to run it as a scheduled task (it is supposed to update data that is pulled from a SQL Server at regular intervals), it fails with the following error:
Microsoft Office Excel cannot access the file 'c:\test\SampleWorkbook.xlsm'. There are several possible reasons: .....
The file does exist. The path reported in the error is correct. The account under which the task is running is the same account I use to run it from the command line. User Account Control is not enabled, and the task is set up to run with highest privileges. When I run the same script through the Task Scheduler from a Windows Server 2003 machine, it works without issue.
I was just wondering if somebody on this forum has run into a similar issue in connection with Windows Server 2008 R2 and figured out what the magic trick is to make it work. I'm sure it is rights related, but I haven't quite figured out what which rights are missing.
Thanks in advance for any advice you may have.
All replies
-
Are you running the the command line from a "SERVER" or from your PC? The server will have a c:\ drive as well as a local PC. I would like to see the complete command line that you are using. I wouldn't think you have Excel installed on the Server. So I suspect that the command line is actaully using the excel program on a local PC in the c:\Program File" folder. Somehow the server is referencing a PC drive (not on the server) on a client PC. The C:\ drive also must be referenced on the Client PC or the XLS file must be located on the server c:\ drive.
jdweng- Marked as answer by Bessie Zhao Wednesday, December 15, 2010 7:48 AM
- Unmarked as answer by Gerhardo Friday, January 7, 2011 4:23 PM
-
No. This particular server does have Excel installed and it wasn't referencing some file on a different machine. Below is a simple way to dupe it. Create an excel spreadsheet, and put a macro in it. Save it and then run the macro through the script on Windows Server 2008 R2. It works fine. As soon as you try to run a scheduled task that basically calls the vbscript, it fails when opening the work book.
When I run the same script on Windows Server 2003 through a scheduled task, it works fine.
Thanks.
c:\MyFiles\Test.vbs
contents of vbscript file
filename=c:\myFiles\test.xls
set xlapp = CreateObject("Excel.Application")
xlapp.visible=false
set xlBook = xlapp.Application.Workbooks.Open(fileName)xlapp.Run "UpdateDataSources"
-
I wondering if the problem is with the file extension (XLS vs XLSM). Do you get any errors. I would check on the server the Event Viewer for any error message at the time you scheduled the task.
You also can indlude the servername in the createobject
Set xlApp = CreateObject("Excel.Application", "MyServer")
You may be having problems with the version of excel because your file is an XLS. Creatobject defaults to the version of excel installed on the PC. Try specifying Version 11 which supports XLS files.
set xlapp = CreateObject("Excel.Application.11")
jdweng -
-
You probably would have to build your application using visual Studio (C++, C#, VBnet) using the Office Interop APIs. This will allow you to read office appliations without having the licenses running on the server. The other method would be to run your from a client PC with office installed and login as an administrator to the server.
jdweng -
My server has Excel installed in it and am running the Task as under a System Admin login. I just found that if i choose the Platform as Windows Server 2003, the task does not fail and executes successfully. I'm seeing the problem when the task runs on Windows Server 2008 R2 platform
-
For what it's worth, I ran into this same issue just now but do not currently have the time to look into it further.
i find that with Windows Server 2008, there have been some additional restrictions created when binding to objects when running a scheduled task (in this case, Excel.Application). If you play around with the DCOM config / WMI security / local security policy, you may be able to find the exact permission setting to open up for the Service Batch Account that you are using.
Does the script run successfully when you run the scheduled task as an Administrator?
-
Hi,
Have anyone found a solution to this? I have the same symptom on a Windows 2008 R2 server where the program works as expected but when run from a schedule task the following code (last line) fails:
Dim xlApp As New Excel.Application Dim xlWrkbook As Excel.Workbook Dim xlWrksheet As Excel.Worksheet Dim objCurrentCulture As System.Globalization.CultureInfo 'ställ om kulturen objCurrentCulture = System.Threading.Thread.CurrentThread.CurrentCulture Try System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US") xlApp.Visible = False xlApp.DisplayAlerts = False xlWrkbook = xlApp.Workbooks.Add(strInputFilePath)
I do not understand what is causing this. The schedule task runs with highest privileges and the error message.
Thanks in advance!
Best regards
Lars -
-
Hi, I've also run into this issue on Windows 2008 R2 using Excel 2010 (x64). Never had this problem before with Windows Server 2003.
It appears to start Excel, but then the task just hangs (never ends). I've confirmed that it's not a problem with the script (it runs successfully) and not a related to permissions.
Like VloveSushi, when I set the task type to Windows 2003, it works inconsistently (I haven't been able to find a pattern).
Any insight would be greatly appreciated. Thanks.
-
-
-
-
Googled arouond and found here the solution.
http://forums.techarena.in/windows-security/1297117.htm
Incredible, as I added the following directory c:\windows\syswow64\config\systemprofile\desktop it WORKED. Don't ask my why, seems to be something related to COM calls that faill if this directory is not existing.
Thanks to gregarican for this solution
- Proposed as answer by Swiss Scripter Tuesday, September 13, 2011 7:58 PM
-
Thanks for posting this solution, it also worked for me.
I'm running a Powershell V2 script that does COM calls into an excel.application object, it was failing when invoked via a Scheduled Task on a Windows 2008 R2 x64 server until I created the directory 'c:\windows\syswow64\config\systemprofile\desktop'.
Thanks again.
-
-
-
-
-
-
-
Hi Guys,
I believe I have been struggling with the same, basic issue that is described in these posts. However, the solution which seems to be working for everyone else is not working for me. Perhaps, I am misunderstanding or incorrectly implementing it. Can someone confirm, if I am correctly or incorrectly implementing the solution (aka the addition of the "c:\windows\syswow64\config\systemprofile\desktop" directory)?? thanks.
More detail on my specific situation:
1) I am attempting to schedule tasks in Task Scheduler which opens an excel spreadsheet at specific times each day on a Windows-based server. Upon opening, the excel spreadsheet should automatically run a series of VBA macros (all of this works on my home PC).
2) My server OS is Windows Server 2012.
3) Once I have configured a task in the server Task Scheduler, it fails to launch excel at the time specified in the "trigger" tab. (I am using task configurations/settings identical to those in tasks I have created in the Task Scheduler on my home PC that run flawlessly).The "history" tab (on the server task) claims, after the specified trigger time, that "Task triggered on scheduler," "Task Engine recieved message to start task," "Task Started," "Created Task Process," "Action Started." However, excel has not actually started and nothing else happens going forward.
4) Additionally, in a given new task, on the "general" tab, I am given 4 options:1.Windows Server 2012
2.Windows 7, Windows Server 2008 R2
3.Windows Vista, Windows Server 2008
4.Windows Server 2003, Windows XP, Windows 2000
As "VLoveSushi" mentioned, the task in question will launch excel (et al) succesfully according to my settings, if I configure the task with option 4 (Windows Server 2003). However, If I configure the task with one of the first three options, the task fails to launch excel as I described above in detail #3.
5) After reading all the posts here, I decided to try the "c:\windows\syswow64\config\systemprofile\desktop" solution, which many of you said has worked for you. To me, implementing that solution meant simply creating an empty folder called "desktop" with path "c:\windows\syswow64\config\systemprofile\" on my server. Doing so hasn't appeared to solve anything, as I am still unable to configure tasks using option 1-3. To this end, was adding that directory, as I did, all I needed to do? Was I supposed to associate that new directory to my server's Task Scheulder in some way?
Also, please keep in mind, while I am fairly savvy at writing VBA (and a little SQL) for Excel and Access, this is my first experience on a server.
Thanks in advance for you help!
-Stan -
Hi,
I am struggling with an issue similar to this post.
I have create an windows application using C# code which uses Microsoft.Interop.Excel to create export data from database to excel. I have created a schedule task in Windows Server 2008 R2 to execute the same every morning at 6:30 AM.
When I run the task manually, it works fine and creates the excel file, but the task fails at 6:30 AM every morning.
It seems like, I have to manually execute the task every day, after I manually execute the task, it works fine for the day, either I run manually or set some other time in the schedule task.
Please let me know if you have came across any such issue.
Abhijit
Abhijit Sil
-
Hi,
i have the same problem. When i run a C# program which uses the Microsoft.Interop.Office.Excel manually on a Windows Server 2012 then it runs without errors. As scheduled task it creates at following code:
try
{
wk=excel.Workbooks.Add(Type.Missing);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
following error:
Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to
I added also in the C# program a memory counter to see, how many memory is available at the time, when this error happens. Here the added code:
ramCounter = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes");
Here the result: Available Memory: 1128 MB
So i think it should be enough to add a new empty Excel-Workbook.
Strange, that Microsoft takes so long to solve that problem or at least to tell us normal users, what the workaround could be. Is Microsoft not looking in such forums? Where we have to put such problems?
elu
elu
-
The issue has to do with the way the default environmental settings are configured on the PC. Did you try the fix that everybody else used? I suspect the TEMP foler that windows is using for swap space isn't configured properly. Try emptying the folder c:\windows\temp
jdweng
-
-
When you schedule th etask make sure you set the crendentials to a user account. You may want to try as an administrator to see if that helps. the problem has nothing to do with Excel, it has to do with the environmental settings that the task is running under.
You may want to look at the website below to see if anything on the webpage helps. I would look at the tuning issues that are related to the user accounts, environmental variables, and running tasks.
http://www-01.ibm.com/support/docview.wss?uid=swg21591294
jdweng
-
Same issue here. One more variable in the equation, this scheduled task worked fine until we upgraded from Office 2007 to 2013. The vbs script works fine if I run it manually but as a scheduled task, the job fails because it is unable to open the excel file only when run as a scheduled task. I have everything set to run with elevated privs and run as an administrator account id. As I said, this task worked fine until we upgraded to office 2013 on that system.
-
i found some other detail to my issue above:
when i start the program an event is created in the event logger under "Microsoft Office Sessions":
ID: 1, Application Name: Microsoft Office Excel, Application Version: 12.0.6665.5003, Microsoft Office Version: 12.0.6612.1000. This session lasted 26 seconds with 0 seconds of active time. This session ended normally.
So it seems, that the rights are enought to start Excel, but something is preventing to create a new Excel-workbook.
Does someone know, how it is possible to inform a Microsoft Windows Server 2012 developer, to have an official statement about that problem?
elu
-
Thanks!!!
- Proposed as answer by JasonDWilson77 Monday, October 7, 2013 5:40 PM
-
Circling back to this after sometime as I see this is not marked as Answered. I had to create this folder "c:\windows\syswow64\config\systemprofile\desktop " in both the syswow64 directory and the non-syswow64 directory to fix this issue. Not sure both were necessary, but after the syswow64 was created my issue still existed, so I created the other one and the issue was resolved. Thanks to everyone who posted on this!
- Proposed as answer by FosterHardie Monday, December 9, 2013 7:19 PM
-
Go to Trust center settings in EXCEL (as the needed user) and deaktivate the standard settings, allow access through deactivation of all checkmarks.
(and choose the first point of three available options below, and confirm witk OK.)
- Edited by drapoel Tuesday, November 12, 2013 4:21 PM
-
Can I ask more about you program? Are you writng macros in an excel workbook or are you writing a VS application. It is easier for a VS application to pull data directly from the database than to use an intermediate excel file.
I would first check the Event in Start - Administarative tools - Event viewer to see what error messages are bing generated. Can you open the excel file manually to verify the excel file being generated is good. This posting originally was started due to problems open an excel file in a service. Your problem seems to be in generating an excel file in a service. I would first make sure there is an excel license on the server and that a good excel file can be opened on the server. Are you accessing the excel file on the server PC or through a network drive?
Normally an excel file will not have an extension shown if excel insn't installed n the PC. without excel installed the PC (or server) will not recognize the excel extensions. I also suspect that the window explorer you are using has the setting "Hide extnesions for known file types" set so you aren't seen the xls extension.
jdweng
-
-
-
-
-
This is truly killing me ... trying to get it working on Windows Server 2012 without success.
I desperately need to automate running Excel macros in a "headless" environment, that is non-interactive, non-GUI, etc.
I can get it to work using Excel.Application COM, either via VBScript or Powershell, successfully on many other Windows systems in our environment - Windows Server 2008 R2, Windows 7 (32-bit), etc., -BUT-
The two servers we built out for running our automation process are Windows Server 2012 (SE) - and it just refuses to run on the 2012 servers - it gives the messages below from VBScript and PowerShell, respectively-
I have tried uninstalling and re-installing several different versions of Microsoft Excel (2007 Standard, 2010 Standard, 2010 Professional Plus, 32-bit vs. 64-bit, etc.), but it makes no difference.
Would be extremely grateful if any one out there has had any success in running Excel automation on Server 2012 in a non-interactive environment that they could share.
( I have tried adding the "%windir%\syswow64\config\systemprofile\desktop" folder, which did fix the issue for me when testing on Windows Server 2008 R2, but sadly did not resolve it on Windows Server 2012 )
------------------------------------------------------------------------------------------------------------------------------------
[VBScript error msg]
Z:\TestExcelMacro.vbs(35, 1) Microsoft Office Excel: Microsoft Office Excel cannot
access the file 'Z:\TestExcelMacro.xlsm'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open work[Powershell error msg]
Exception calling "Add" with "0" argument(s): "Microsoft Office Excel cannot open or save any more documents because th
ere is not enough available memory or disk space.
To make more memory available, close workbooks or programs you no longer need.
To free disk space, delete files you no longer need from the disk you are saving to."
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ComMethodTargetInvocation
You cannot call a method on a null-valued expression.
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
-
Googled arouond and found here the solution.
http://forums.techarena.in/windows-security/1297117.htm
Incredible, as I added the following directory c:\windows\syswow64\config\systemprofile\desktop it WORKED. Don't ask my why, seems to be something related to COM calls that faill if this directory is not existing.
Thanks to gregarican for this solution
-
Same issue here.
Old server, Server 2003/Office 2003. Scheduled task worked great. No issues.
Now...
Server 2008 R2/Office 2010. Scheduled task fails. Lots of pissed off people
I created the folder for both the System32 and SysWow64 directories and it doesnt work
They want to know why it worked before and it doesnt work now and I have no answers for them except Microsoft changed something
This is really frustrating
Warm Fuzzies!
-
Googled arouond and found here the solution.
http://forums.techarena.in/windows-security/1297117.htm
Incredible, as I added the following directory c:\windows\syswow64\config\systemprofile\desktop it WORKED. Don't ask my why, seems to be something related to COM calls that faill if this directory is not existing.
Thanks to gregarican for this solution
Worked great, solved the problemIn this article, what exactly does he mean "You must allow it to run through console. You can reschedule the task and it would give you option to work on the same.?
Thanks
Warm Fuzzies!
-
-
-
Just install office and use powershell to create an new COM object. Works great. If you don't want to install the full version I think the dev tools work the same. You can use powershell to manipulate the data however you want and it runs under a scheduled task just fine . Been using it to process new users from a export
Warm Fuzzies!
-
Can somebody please share the solution for this issue?
I am facing similar issue with Windows 2012 R2 OS and Excel 2007 combination.
I tried couple of things like Excel is able to Open an existing workbook on my system but fails to create a new Workbook as done by invoking the "Add" command. It fails with Error 800a03ec.
I tried creating the two folders i.e. C:\Windows\SysWOW64\config\systemprofile\Desktop & C:\Windows\system32\config\systemprofile\Desktop, but could not get it working.
-
I am having a similar issue: I have a c# application that builds an Excel (.xlsx) file. I use Microsoft.Office.Interop.Excel to accompish this. I used to run the application from scheduled Tasks on a Windows Server 2003. No problems. My company recently upgraded the server to Windows Server 2008. In my case, Excel is installed on the server. Now the application will work fine from a comand prompt on the new server, but it fails when run from the Task Scheduler. Specifically, I have observed the following statements failng (throwing an exception):
xl.SheetsInNewWorkbook = 1; [ where xl is the name of my Application instance]
workbook.Save(true, "path_to_save.xlsx", Type.Missing.Value);
I also noticed that xl.Visible=true fails. This is not a big deal. I turn this off when running from scheduled tasks anyway. I just forgot to do this. I mention it only because our old Windows Server 2003 does not balk at this.
I have set up the Task Scheduler to run this application from a Domain user account that is a member of the Server's Administrators group, have cecked Run whether user is logged on or not (with Do not store password unchecked). I have also checked Run with highest privleges.
- Edited by Mark9638 Friday, May 22, 2015 4:06 PM
-
Hi Mark9638,
try to enter with the Domain user account with which the scheduled task runs and start it manually. Probably you see more. Could be that it has to do with the missing right to save the workbook on a specific path, which you have to change in the excel under the excel options for trustworthy places to save.
regards
elu
elu
-
-
After some searching I found this article and at first didn't believe it would work. Just creating an empty folder!! But I did and the scheduled tasks run smoothly. If this is so important for running scheduled tasks why didn't Microsoft already create this folder "desktop" or at least show some intelligent error message to point you in the right direction like "You are missing folder desktop on location ..."
Thanks for finding this
-
I have had a same issue on my Server 2012. It worked on Server 2008 after adding a desktop top folder but not in 2012. Has anyone found a solution, please post it here or email at hungtdao@yahoo.com. Thanks in advance.
-
I managed to solve my issue by following the methods outlined in below link :
In additions to these 2 folders :
C:\Windows\System32\config\systemprofile\Desktop & C:\Windows\sysWOW64\config\systemprofile\Desktop
Add 2 more folders :
C:\Windows\SysWOW64\config\systemprofile\Documents C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache
https://social.technet.microsoft.com/Forums/windowsserver/en-US/aede572b-4c1f-4729-bc9d-899fed5fad02/run-powershell-script-as-scheduled-task-that-uses-excel-com-object?forum=winserverpowershell
- Proposed as answer by M.Henning Monday, March 7, 2016 12:09 PM
-
I have had a same issue on my Server 2012. It worked on Server 2008 after adding a desktop top folder but not in 2012. Has anyone found a solution, please post it here or email at....Thanks in advance.
It is amazing that this issue has been around for five years and still no solution that works for everyone. I have this same issue- just upgraded to Server 2012 and the program we ran as a scheduled task in Server 2003 fails. I can run it fine if I run it manually. The program I have problems with calls an Excel spreadsheet, then merges it with others and uses Adobe Distiller to create a PDF. I get the "filename or path does not exist" error. Adding the two new desktop folders in syswow64 and system 32 just changed the error from filename does not exist to "no printers installed". Even though the Adobe PDF printer is installed. I just can't believe it's this difficult to identify the security change from Server 2003 to 2012 that causes this. I'm pulling what little hair I have left out! -
-
Creating the folders described above isn't enough. You have to give your account (the account the task is running under) permissions to them.
Here are detailed instructions of all the permissions needed. This worked for me in Windows 2012:
http://troyvssharepoint.blogspot.ca/2012/07/stumbled-upon-interesting-one-today.html
- Edited by cybersaga Friday, April 22, 2016 3:14 PM
-
-
-
-
-
cybersaga,
Sorry you keep getting emails but this is still not resolved. I have tried everything up to this point that was stated above and it is not working. I agree with a previous statement that it have been since 2011 and this is still not resolved.
Any help?
-
-
-
-
-
-
-
Wow. This is incredible that it still works after all these years. The link in this article doesn't work anymore. I had to write about it:
http://danblee.com/opening-an-excel-workbook-fails-when-run-from-scheduled-task/
-
-
I have the same problem with server 2012r2 and I never manage to get it to work. Instead, I try to work on windows 10. By adding these four folders, scheduled task creates excel and saves excel file on windows 10. But then the creators edition update (or some other monthly updates, these updates always remove your changes, very annoying) erases it all and I have to add the four folders back for it to work again. Hopefully this helps others too.
- Edited by George_2011 Thursday, July 27, 2017 4:42 PM
-
-
-
These two folders are still needed in Windows 10 in February 2018 and works a treat! Too bad I spent 3 hours yesterday debugging my powershell code, only to find a missing system folder fixes the problem!
The first one (below) existed in Windows 10 but NOT the second folder. Once that was created, my powershell script now opens Excel files when called from a scheduled task.
C:\Windows\sysWOW64\config\systemprofile\Desktop
C:\Windows\System32\config\systemprofile\Desktop
THANK YOU!- Edited by gpf nz Monday, February 26, 2018 6:12 PM
-
-
-
Sloved problem for myself.
Task:
- Windows Server 2012 R2 & Excel 2016;
- Run .vbs script that uses Excel.Application COM and opens network (shared) file.
- This needs to be done as a scheduled task running under unprivileged user while user is not logged on.
Solution:
- Install 32-bit Excel
- Create a security group for 'scheduled task' users (we use separate server for running scheduled jobs, so we have one) - Let's name it 'SchTskUsers'
- Grant SchTskUsers 'logon as batch job' permission: GPEDIT.MSC -> Computer > Windows > Security > Local > User > Logon as batch job;
- Grant SchTskUsers run components permission : c:\windows\syswow64\dcomcnfg.exe, right click [My Computer], select tab [COM Security], in [Launch and activation permissions] group press [Edit default] and add SchTskUsers with [Local launch, Local
Activation] permissions.
NOTE: In this example I am granting this permission for all applications. That is not too secure, so it is better to grant it per-application, possibly! - On this step, we can run Excel from unprivileged batch user, but we can not open files if Excel was run from scheduled task :-( . I think It's a bug: in this way, Excel.exe tries to write to %WINDIR%\SysWOW64\Config\systemprofile\AppData\Local istead of %USERPROFILE%, and, because user who runs Excel does not have any permissions for this folder (He is not Administrator), this fails.
- Make 'Desktop' folders in System profile. I am not sure it is required in Excel 2016, but, as Internet says, Excel 2007 made an error because of this folder was missing.
mkdir "%WINDIR%\SysWOW64\Config\systemprofile\desktop" mkdir "%WINDIR%\System32\Config\systemprofile\desktop"
- Grant full control permissions on System profile for Scheduled Task group:
icacls "%WINDIR%\SysWOW64\Config\systemprofile" /grant SchTskUsers:(OI)(CI)F icacls "%WINDIR%\System32\Config\systemprofile" /grant SchTskUsers:(OI)(CI)F
NOTE Possibly there is more granular way to grant permissions, or there is a way to make Excel not use system profile. I do not know it.
- Edited by FilimoniC Monday, August 13, 2018 1:39 PM
-
-
-
I have a MS Access application that could be manually run without issue, but when scheduled in Task Scheduler it would return the error: Object variable or With block variable not set. I was so relieved to find Swiss Scripter's solution, all I had to do was add a "desktop" folder to this existing path on our 2016 server: c:\windows\syswow64\config\systemprofile\desktop. No more problem! : )
David Rowland
-
-