2

I am trying to run a VBScript but CFExecute throws an error

<cfexecute name = "C:\Windows\System32\CScript.exe" 
            arguments = "//NoLogo D:\Excel.vbs D:\test.xls"
            variable = "data"
            timeout = "100">
 </cfexecute>
<cfdump var="#data#">

Error:

 Error: 424 Source: Microsoft VBScript runtime error Description: Object required 

But when I run the VBScript with CMD it works fine

C:\Windows\System32 > cscript //nologo D:\Excel.vbs D:\test.xls

I have full admin access, so why am I getting this error?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Sks
  • 612
  • 7
  • 23
  • 2
    *You* have full admin rights... but does the account that ColdFusion is running as have them? – Adam Cameron Aug 29 '14 at 09:51
  • @AdamCameron Yes they have. – Sks Aug 29 '14 at 09:58
  • 1
    Stick the full command & params in a batch file, and `` that. – Adam Cameron Aug 29 '14 at 10:00
  • Checked with batch file: @echo off pushd %~dp0 cscript //nologo D:\Excel.vbs D:\sham.xls Same error, let me check with Network Admin here. – Sks Aug 29 '14 at 10:45
  • Cool. I'd manually confirm that the account CF is running as has the appropriate effective permissions. Don't assume: *check*. Just to remove it as a factor. – Adam Cameron Aug 29 '14 at 10:56
  • Found Solution: It was due to bug in the Windows 2008 server http://social.msdn.microsoft.com/Forums/en-US/b81a3c4e-62db-488b-af06-44421818ef91/excel-2007-automation-on-top-of-a-windows-server-2008-x64?forum=innovateonoffice For office automation (accessing via script and non-window based operation) we have to add Desktop folder inside C:\Windows\System32\config\systemprofile C:\Windows\SysWOW64\config\systemprofile I added it and found success – Sks Aug 29 '14 at 16:14
  • could you please blog this? – Adam Cameron Aug 29 '14 at 20:55

2 Answers2

7

It was due to bug in the Windows 2008 server. For office automation (accessing via script and non-window based operation) we have to add a "Desktop" folder inside

C:\Windows\System32\config\systemprofile
C:\Windows\SysWOW64\config\system32

I added it and found success.

Sks
  • 612
  • 7
  • 23
  • Thanks for posting the solution. Just curious, did you have to create a "Desktop" subfolder in both locations? The thread made it sound like it depending on your o/s, ie `SysWOW64` for 64bit and `System32` for 32bit. – Leigh Aug 29 '14 at 20:25
  • 2
    Yes @Leigh Desktop folder needs to be created at both directories. – Sks Aug 30 '14 at 02:49
0

Create a vbscirpt file (.vbs). The code content would have the task you want to achieve.

The below example contains the vbscript file, that refreshes the excel and the cfm which executes the vbscript.

Sample vbscript file code:-

Set fso = CreateObject("Scripting.FileSystemObject")
Set xl  = CreateObject("Excel.Application")
xl.Visible = True

For Each f In fso.GetFolder("C:\inetpub\WebSites\Upload\").Files
  If LCase(fso.GetExtensionName(f.Name)) = "xlsx" Then
    Set wb = xl.Workbooks.Open(f.Path)
    wb.RefreshAll
    wb.Save
    wb.Close
  End If
Next

xl.Quit

Sample cfm file code:-

<cfexecute name = "C:\Windows\System32\cscript.exe" arguments = "C:\inetpub\WebSites\CSAT\test.vbs">
</cfexecute>
Anit Kumar
  • 1,228
  • 8
  • 16