duanchi19820419 2012-09-26 15:25
浏览 95


There is a vbscript that we must run to consolidate information gathered in a custom web application into our management software. The .vbs is in the same folder as the web application which is built in CodeIgniter 2.

Here is the controller code:

public function saveToPM( $budgetType ){
    // run it 
    $obj = new COM( 'WScript.Shell' ); 

    if ( is_object ( $obj ) ) { 
        $obj->Run( 'cmd /C wscript.exe D:\pamtest\myload.vbs', 0, true );
    } else { 
        echo 'can not create wshell object'; 
    } // end if

    $obj = null;

} // end saveToPM function

We have enabled DCon in the php.ini file and used dcomcnfg to enable permissions for the user.

I borrowed the code from http://www.sitepoint.com/forums/showthread.php?505709-run-a-vbs-from-php.

The screen echos "Code executed" but the vbscript does not run.

We have been fighting with this for a while so any help is GREATLY appreciated.

  • 写回答

2条回答 默认 最新

  • duanraa1984 2012-09-27 06:47

    It's a bit messy. PHP calls WScript.Shell.Run which will call cmd (with /c - i.e terminate cmd.exe when it's done its thing) which will call cscript.exe to run and interpret a .vbs. As you can see quite a few things that have to go right! :)

    What if you 'wait' for the WScript.Shell.Run call to end (your $wait variable) before continuing execution of the wsh script which will in turn allow PHP to continue execution etc?

    Since you're not waiting for the call to finish, PHP thinks its all good and continues onto the next line (interpreted language).

    Also, maybe have the .vbs create an empty text file? Just so you have an indication that it has actually run.

    Just take a step back, have a beer and it'll come to you! Gogo troubleshoot!

    And - http://ss64.com/vb/run.html

    If bWaitOnReturn is set to TRUE, the Run method returns any error code returned by the application.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥30 关于#c++#的问题,请各位专家解答!
  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)
  • ¥15 w3wp,exe 中发生未处理的 Microsoft ,NETFramework 异常。
  • ¥20 C51单片机程序及仿真(加减器)
  • ¥15 AQWA | 水动力分析 二阶波浪力
  • ¥15 c语言题目:成绩管理系统