1

I have a VBS script which when run from the command line runs perfectly, but when I try to execute the script via CFEXECUTE the script does not seem to run (the file which should be created is not created).

The following text appears in my browser window when I run the page containing the CFEXECUTE tag:

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.

My code is:

<cfexecute name="C:\Windows\System32\cscript.exe" arguments="D:\path\to\script\myscript.vbs" timeout="30">

Does anybody know why it might not be running correctly?

Update:

If I use the code below instead of CFEXECUTE the value of result is 0, which I believe means the script ran without error. But the file which should have been created still hasn't been created.

<cfset command = "C:\Windows\System32\cscript.exe D:\path\to\script\myscript.vbs"> 
<cfset runTime = CreateObject("java","java.lang.Runtime").getRuntime()> 
<cfset process = runTime.exec(command)> 
<cfset result = process.waitFor()> 
<cfoutput>#result#</cfoutput>

The VBS script:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("D:\path\to\xls\file\containing\html.xls")
objExcel.Application.Visible = False
objExcel.Application.DisplayAlerts = False
objExcel.ActiveWorkbook.SaveAs "D:\path\to\new\xlsx\file.xlsx", 51
objExcel.ActiveWorkbook.Close
objExcel.Application.DisplayAlerts = True
objExcel.Application.Quit
WScript.Quit 
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Michael
  • 1,643
  • 1
  • 15
  • 31
  • 2
    What is the error you get. Di you try dumping the value? You can try running the service from command prompt and execute your page. This would append exception if any to the command prompt. – Anit Kumar Apr 03 '14 at 14:15
  • Also, try removing the timeout, as it may require more time to execute. – Anit Kumar Apr 03 '14 at 14:16
  • Removing the timeout did not help – Michael Apr 03 '14 at 14:17
  • For CF10, Stop ColdFusion service - Launch Command prompt as Administrator - Browse to cf_root\cfusion\bin and run the following command coldfusion.exe -start -console For CF9, Stop ColdFusion service - Launch Command prompt as Administrator - Browse to cf_root\runtime\bin and run the following command jrun.exe -start coldfusion – Anit Kumar Apr 03 '14 at 14:18
  • 3
    Bloody hell, @Anit ... couldn't he just look @ the error logs!? – Adam Cameron Apr 03 '14 at 14:40
  • I am assuming that @Michael might have already checked the logs :-) – Anit Kumar Apr 03 '14 at 14:45
  • I haven't done. Which error log file would I need to look in? – Michael Apr 03 '14 at 14:58
  • 2
    coldfusion-error, exception and application logs at \ColdFusion10\cfusion\logs – Anit Kumar Apr 03 '14 at 15:00
  • Nope, no errors in those logs relating to this problem :( – Michael Apr 03 '14 at 15:04
  • I am not VB programmer. I did bit of google and composed this code you can try. 'Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("D:\path\to\xls\file\containing\html.xls") strSavedOutput="D:\path\to\new\xlsx\file.xlsx" objExcel.Application.Visible = False objExcel.Application.DisplayAlerts = False objExcel.ActiveWorkbook.SaveAs strSavedOutput, 1 objExcel.ActiveWorkbook.SaveAs strSavedOutput, 51 objExcel.Application.DisplayAlerts = True objExcel.ActiveWorkbook.Close objExcel.Application.Quit WScript.Quit ' – Anit Kumar Apr 03 '14 at 16:28
  • 1
    No one mentioned errorVariable? If specified, cfexecute will stuff any error result into it. – Raymond Camden Apr 03 '14 at 17:58
  • Just a guess, but try running it [batch mode](http://technet.microsoft.com/en-us/library/bb490816.aspx) and suppressing the logo, ie: `arguments="//B //NoLogo c:\path\to\file.vbs" ` – Leigh Apr 03 '14 at 19:04
  • After a bit more research I think this might be a permissions issue. What permissions does the ColdFusion user need for this `cfexecute` to work and how do I tell if it does/doesn't already have them? Although would I be seeing the Microsoft logo text if the user didn't already have the correct permissions? – Michael Apr 03 '14 at 20:30
  • 1
    Did you check the windows Event viewer logs, if it turns out to be a permission issue. – Anit Kumar Apr 03 '14 at 21:30
  • Thanks for all the help on this. The event viewer helped me identify this as a permissions issue which is now fixed but I keep running into new errors. I am starting to feel that this will not be a robust way to achieve what I want. What I need to do is convert an XLS spreadhsheet written in HTML into a format which CF's spreadsheet functions can use (i.e. OpenXML). Does anybody have any other ideas of how I might achieve this? – Michael Apr 04 '14 at 11:03
  • Would it be possible for me to use this .NET library from my CF code? https://html2openxml.codeplex.com/ – Michael Apr 04 '14 at 11:05
  • @Michael Please up-vote and mark the thread as answered. You an open a new thread for the new issue – Anit Kumar Apr 04 '14 at 13:21
  • If you're running on W 2008 I believe this is your answer: [http://stackoverflow.com/questions/25565565/run-vbscript-using-cfexecute-throws-error-but-works-fine-via-command-line][1] [1]: http://stackoverflow.com/questions/25565565/run-vbscript-using-cfexecute-throws-error-but-works-fine-via-command-line – gordon Dec 08 '14 at 14:47

0 Answers0