简体   繁体   中英

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

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?

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM