Microsoft Excel - Permission Denied Error for CreateObject("Excel.application")
Asked By Shashin Surkund on 09-Aug-10 06:51 PM
I'm getting a VBScript Error (70: Permission Denied) when my VBScript runs via the Windows Scheduler and I try to create an instance of Excel.application [Set mobjExcel = CreateObject("Excel.Application")]. This is only happening on some of our production servers. It works fine on or DEV/QA servers. All servers have Same OS (Windows 2003 R3) .The same code runs successfully on the production in the following instances:
1> If I run it manually.
2> If I do a logon to the Server as the same user and the scheduled script runs in my shell.
Code Snippet:
Here is a test script. code fails on Set mobjExcel = CreateObject("Excel.Application")
------------------------------------------------
Option explicit
Public gobjFSO
'__________________________________________________________________________________
Call Main
'__________________________________________________________________________________
Sub Main()
On Error Resume Next
Dim mblnstatus
Dim mfhLogFile
Dim mstrFilePath
Dim mstrCurrProcessPath
Dim mobjExcel
Set gobjFSO = CreateObject("Scripting.FileSystemObject")
mstrCurrProcessPath = ThisWorkbook.Path
If Err.Number > 0 Then
Err.Clear
mstrCurrProcessPath = gobjFSO.GetAbsolutePathName(".")
End If
mstrFilePath = mstrCurrProcessPath & "\" & "Exceltest.log"
If gobjFSO.fileexists(mstrFilePath) = True Then
Set mfhLogFile = gobjFSO.OpenTextFile(mstrFilePath, ForAppending)
Else
Set mfhLogFile = gobjFSO.CreateTextFile(mstrFilePath, ForAppending)
End If
Set mobjExcel = CreateObject("Excel.Application")
If (Err.Number <> 0) Then
mfhLogFile.WriteLine ("Error creating instance of Excel Object. Error Details: " & Chr(10) & _
Err.Number & ": " & Err.Description)
Else
mfhLogFile.WriteLine ("No Error Writing to Audit File")
End If
mfhLogFile.Close
mobjExcel.Application.Quit
Set mobjExcel = nothing
Set gobjFSO = nothing
End sub
---------------------------------------------------
Any help/input ?
Thanks
sincerely
Shashin
Venkat K replied to Shashin Surkund on 09-Aug-10 10:22 PM
The Error message "Run-time error '70: Permission denied" is a write-protected message.
Just make sure you are not creating Excel where you don't have access to create. Make sure the you have write access on the path where you are trying to create the Excel file.
Publishing to a write-protected disk or that the files you are replacing with the newly published files are not opened by another application.
Thanks,
iHelper MS replied to Shashin Surkund on 09-Aug-10 10:38 PM
Windows 2003 R3? or Windows 2003 R2?
I notice that you are using both CreateObject("Scripting.FileSystemObject") and CreateObject("Excel.Application") commands. Are you sure that the 1st FileSystemObject line is executing well?
I guess the Task Scheduler service runs by default as the Local System Account. Try this:
Goto Control Panel -> Services -> double click on Task Scheduler service.
Goto Log On tab and if Local System Account is selected, choose the checkbox "Allow service to interact with desktop"
Save the changes and re-run your job.
Hope this helps.
-iHelper MS
Shashin Surkund replied to iHelper MS on 09-Aug-10 11:11 PM
CreateObject("Scripting.FileSystemObject") is working fine. as I'm able to write the error to the log file i create
the script completes as i'm trapping the error.
I also modified the script to put an err.clear just before CreateObject("Excel.application"). Error is coming on that command.
Also, the same script runs fine when I run it manually, when i login as the same user. It also runs fine thru the schduler when I'm logged in and the Scheduler uses my shell to run the process.
Shashin Surkund replied to Venkat K on 09-Aug-10 11:14 PM
CreateObject("Excel.application") is not opening an Excel File. This command only gives me an instance to the Excel COM Object. Also the user has write permissions to the disk where I'm trying to perform my operations.
My actual produciton script then opens the excel file that i'm using and does a lot of stuff. I created a test script just to simulate the error I'm facing.
iHelper MS replied to Shashin Surkund on 10-Aug-10 11:10 AM
Can you experiment the "Allow service to interact with desktop" option in Control Panel -> Services that I provided you above.
Shashin Surkund replied to iHelper MS on 10-Aug-10 11:20 AM
doing it right now :)..sorry i missed that . will let you knwo if that resovled the issue
Shashin Surkund replied to iHelper MS on 10-Aug-10 12:24 PM
Hi iHelper MS,
<<I guess the Task Scheduler service runs by default as the Local System Account. Try this:
Goto Control Panel -> Services -> double click on Task Scheduler service.
Goto Log On tab and if Local System Account is selected, choose the checkbox "Allow service to interact with desktop">>
That did not help. I'm still getting the same error
iHelper MS replied to Shashin Surkund on 10-Aug-10 12:38 PM
Let me try to simulate this. What is the version of MS Office you are using?
iHelper MS replied to Shashin Surkund on 10-Aug-10 01:09 PM
I am not sure how your Constants are getting picked up. Do you mind to change your script?
Find "ForAppending" and replace it with "8" (without double codes)
iHelper MS replied to Shashin Surkund on 10-Aug-10 01:21 PM
Here are some more queries and pointers for you:
1) How exactly have you scheduled the task? At what time this task runs?
2) Is this task failing always on Production server or its failing at random intervals?
3) Explore the Task Logs to identify more details. For this, goto:
Start -> Programs -> Accessories -> System Tools -> Scheduled Tasks. Advanced menu -> View Log.
Shashin Surkund replied to iHelper MS on 10-Aug-10 01:26 PM
The task does not fail as I'm capturing the error and logging it to a log file. In VB Script you need to have "On error resume next" and then catch your errors by checking err.number.
The task is schduled to run every 10 minutes. It runs fine when I'm currently logged into the server and Task Schduler uses my shell to run the process.
Once I log out and the process runs the next time, it fails exactly at the point when it is trying to get an isntance of Excel.application. I'm thinking this provblem is got to do with Office Automation and Security and there may be a patch available for this :O(.
This same process is running fine on another server. Only difference I found was that server has a later version of Office. Both Servers have Windows 2003 SP2 and WSH version is 5.6
iHelper MS replied to Shashin Surkund on 10-Aug-10 01:31 PM
Yes, I agree with you on the On Error Resume Next concept.
But, you are bit confusing me. Your 1st question said Windows 2003 R2 and now you say Windows 2003 SP2.
Please confirm these versions:
- Windows Server 2003 SP2 (its not R2)
- WSH version is 5.6
- MS Office version?
iHelper MS replied to Shashin Surkund on 10-Aug-10 01:43 PM
I tried 1 minute option and logged off. The job was still running in background.
I am unable to simulate this problem on my sandbox, which has following config:
OS - Microsoft Windows [Version 5.2.2026]
Microsoft Office Excel 2003 (11.5612.5606)
c:\windows\system32\scrrun.dll - 5.6.0.8832
Can you also provide your exact versions in your Production to investigate this further.
Shashin Surkund replied to iHelper MS on 10-Aug-10 01:51 PM
Sorry about the confusion
Here are the correct versions of the server where it is failing
OS: Windows 2003 R2 (Service Pack 2)
WSH Version: 5.6
Office Version: 2003 (11.8231.8221) SP3
On anther server where the process works
OS: Windows 2003 R2 (Service Pack 2)
WSH Version: 5.6
Office Version: 2003 (11.8324.8324) SP3
One more thing to add. I replaced Excel.application with Word.application and got the same error. This tells me that this issue is related bug w.r.t. office automation.
Thanks for all your help
Shashin
9196994378
iHelper MS replied to Shashin Surkund on 10-Aug-10 02:28 PM
Thanks for the version details. I was running base version of Office 2003.
After installing SP3 for Office 2003, I am getting the version - 11.8169.8172
Looks like some there are some more Security Patches which will increase this version to match yours, but I am not aware of which Security Update will do this magic.
I retested this case after installing SP3 for Office 2003, but still not facing this problem.
Notice that my version(after SP3) is still lower than your server where it is failing.
Did you get chance to review the Task Scheduler Log file (C:\Windows\Tasks\SchedLgU.txt) This can give you any further hints on the problem.
Shashin Surkund replied to iHelper MS on 10-Aug-10 02:35 PM
The Task schdukler log is of no help as it is not providing any additional details
Here is a snippet form the log file [Excel_Test.vbs is my test script vb script]
"Excel_test.job" (Excel_Test.vbs)
Started 8/10/2025 11:30:00 AM
"Excel_test.job" (Excel_Test.vbs)
Finished 8/10/2025 11:30:00 AM
Result: The task completed with an exit code of (0).
"Excel_test.job" (Excel_Test.vbs)
Started 8/10/2025 11:35:00 AM
"Excel_test.job" (Excel_Test.vbs)
Finished 8/10/2025 11:35:00 AM
Result: The task completed with an exit code of (0).
"Omniture_Dashboard_Status.job" (DOP_Dashboard_Status.vbs)
Started 8/10/2025 11:36:03 AM
"Omniture_Dashboard_Status.job" (DOP_Dashboard_Status.vbs)
Finished 8/10/2025 11:36:33 AM
Result: The task completed with an exit code of (0).
"Excel_test.job" (Excel_Test.vbs)
Started 8/10/2025 11:40:00 AM
"Excel_test.job" (Excel_Test.vbs)
Finished 8/10/2025 11:40:00 AM
Result: The task completed with an exit code of (0).
iHelper MS replied to Shashin Surkund on 10-Aug-10 02:48 PM
Raise "HELP" with your Administator and ask him to patch Office 2003 and make its build number match :)
Shyam replied to Shashin Surkund on 16-Feb-11 03:59 AM
Hi Dear,
Go to your IIS server where the object actually created and Follow the instructions
"Run -> dcomcnfg utility and giving the user "allow" access to "Microsoft Excel Program" (located under DCOM Config)"
This surely fix the issue with the Excel.application object.
Shyam
David Kieffer replied to Shashin Surkund on 06-Mar-12 02:36 AM
Hello Everyone,
Was the root cause of this issue ever found? I am facing a similar issue/error.
We have code that uses the createObject,
...
...
CreateObject("Word.application")
...
When the above code is run (from an exe), we get the following error in the log it produces:
70: Permission denied
The frustrating issue is, some of our servers run the code fine, other produce the error. What we have found is that all of our Physical Servers produce the erorr, but our Virtual Servers run it fine - no error.
Was there a resolution to the original post/topic here? We are facing a very similar issue and any help would be great. Thanks in Advance!
Bjorn Leiren replied to David Kieffer on 16-Apr-12 01:50 PM
Same Question as the previous post:
Was a resolution to this problem ever found?
I have the same issue.
I attempt to run the line CreateObject("Excel.application") in a .vbs file.
I can run the .vbs file manually under my own account and it works flawlessly.
But attempts to run in in the Windows Task Scheduler fail.
I am presently moving scripts from a WinXP box with Office 2003 to a Win7 Box with Office 2010.
The script worked in the Task Scheduler on the WinXP/Office 2003 box but does not work on the Win7/Office 2010 box.
If anyone has successfully resolved this issue your help would be greatly appreciated.