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.
我们必须运行一个vbscript,将自定义Web应用程序中收集的信息合并到我们的管理软件中。 .vbs与CodeIgniter 2中构建的Web应用程序位于同一文件夹中。 p>
以下是控制器代码: p>
public function saveToPM($ budgetType){
//运行它
$ obj = new COM('WScript.Shell');
if(is_object($ obj)){
$ obj-> Run('cmd / C wscript.exe D:\ pamtest \ myload.vbs',0,true);
var_dump($ obj - >运行);
} else {
echo'无法创建wshell对象';
} //结束如果
$ obj = null;
// $ this-> load-> view('goodPush');
} //结束saveToPM函数
code> pre>
我们在php.ini文件中启用了DCon,并使用dcomcnfg为用户启用了权限。 p>
我借用了 http://www.sitepoint.com/forums/ showthread.php?505709-run-a-vbs-from-php 。 p>
屏幕回显“代码已执行”但vbscript无法运行。 p> \ n
我们一直在争取这一点,所以任何帮助都非常感激。 p>
div>
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.
I've tested your code with a stand-alone PHP script (without Codeigniter) on a Windows XP machine, with the PHP 5.4.4 built-in web server, and I've noticed that the vbscript gets executed, but PHP dies (the event viewer shows a generic "Application Error" with ID 1000).
However I've also discovered that removing the "cmd /C" from the command string solves the problem.
Here is the simple script that I've used for my test:
<?php
$obj = new COM('WScript.Shell');
if (is_object($obj)) {
//$obj->Run('cmd /C wscript.exe test.vbs', 0, true); // This does'nt work
$obj->Run('wscript.exe test.vbs', 0, true); // This works
var_dump($obj->Run);
} else {
echo 'can not create wshell object';
}
$obj = null;
?>
And this is my simple "test.vbs" script:
WScript.Echo "vbscript is running"
Another solution that seems to be working (at least on my platform) is the "system" call:
system('wscript.exe test.vbs');
Unfortunately I don't have a 64-bit IIS system to test with, so I can't really say if there are specific problems on this platform, but I hope this helps.