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.
It’s a bit messy. PHP calls
WScript.Shell.Runwhich will callcmd(with/c– i.e terminatecmd.exewhen it’s done its thing) which will callcscript.exeto 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.Runcall to end (your$waitvariable) 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
.vbscreate 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