使用CFExecute运行VBScript会引发错误,但可以通过命令行正常工作

时间:2014-08-29 09:37:25

标签: vbscript coldfusion wsh

我正在尝试运行VBScript,但CFExecute会抛出错误

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

错误:

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

但是当我使用CMD运行VBScript时,它可以正常运行

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

我有完全的管理员权限,为什么我会收到此错误?

2 个答案:

答案 0 :(得分:7)

那是due to bug in the Windows 2008 server。 对于办公自动化(通过脚本和非基于窗口的操作访问),我们必须添加一个&#34;桌面&#34;

里面的文件夹
C:\Windows\System32\config\systemprofile
C:\Windows\SysWOW64\config\system32

我添加了它并找到了成功。

答案 1 :(得分:0)

创建一个vbscirpt文件(.vbs)。代码内容将具有您想要实现的任务。

以下示例包含刷新excel的vbscript文件和执行vbscript的cfm。

示例vbscript文件代码: -

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

示例cfm文件代码: -

<cfexecute name = "C:\Windows\System32\cscript.exe" arguments = "C:\inetpub\WebSites\CSAT\test.vbs">
</cfexecute>