duanchi19820419 2012-09-26 15:25
浏览 95
已采纳

32位PHP可以在64位IIS服务器上运行.vbs脚本吗?

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 );
        var_dump($obj->Run);
    } else { 
        echo 'can not create wshell object'; 
    } // end if

    $obj = null;

    //$this->load->view('goodPush');
} // 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看