Run VBScript using CFExecute throws error but works fine via command line

1.2k Views Asked by At

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?

2

There are 2 best solutions below

2
On

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.

1
On

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>