Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

Aug 31, 2014

Not able to run vbscript using cfexecute on Windows 64 bit Machine - Solution


Goal: To run VBScript using CFexecute using command base script Cscript.exe

Environment:  ColdFusion 10, Windows7 , 64 bit Machine.

My VB Script(Excel.vbs) performs simple office automation .

So first I tried with command line to run Excel.VBS.

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

and got expected o/p Success (Good my Excel VBS is correct)

Now, I have to see whether CF runs correctly or not.
So I use cfexecute to run Excel.VBS.

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


But, I got this error message -

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

Then what is wrong with ColdFusion, same VBScript is running using command line but CFExecute throws error.

So I tried two things :
  •  Checked whether account which runs ColdFusion is having admin rights or not?
    • Yes CF running with Admin privilege.
  • Tried using batch file
    batchFile.bat :
    @echo off
    pushd %~dp0
    cscript cscript //nologo D:\Excel.vbs D:\test.xls

    <cfexecute name = "D:\batchFile.bat"
                       variable = "savedOutput"
                       arguments="/C /Q"
                       timeout = "3600">
     </cfexecute>
    <cfdump var="#savedOutput#">


    Same Error: 424 Source: Microsoft VBScript runtime error Description: Object required
So what will be the solution for this ?
After checking some threads on office automation I found this solution.

We have to add the Desktop folder in the systemprofile and system32 folder to open file by Excel if you have Windows Service or IIS on Windows 7 x64 (dev machine) and Server 2008 x64.

So I added Desktop folder under these 2 directories -
C:\Windows\System32\config\systemprofile
C:\Windows\SysWOW64\config\systemprofile


O/P: Now my cfexecute code gives success and VBScript performs desired office operation.

Also, verify that ColdFusion is allowed to "Interact with Desktop" is enabled or not on Services.

Note: If you are doing office automation then you have to add the Desktop folder inside systemProfile irrelevant of technology you are using under above Environments.

Hope it helps you :)