how to run .vbs from php

I’ve spent several hours searching and trying different things, but I can’t get this script to run. It is called by a web page:

ini_set(‘display_errors’, ‘1’);

if($_POST['store_list'] && $_POST['start_date'] && $_POST['end_date']){
$cmd = 'wscript.exe <path_to_script>/my_script.vbs /store_list:"' . urldecode($_POST['store_list']) . '" /start_date:"' . urldecode($_POST['start_date']) . '" /end_date:"' . urldecode($_POST['end_date']) . '"';

$ws = new COM('WScript.Shell');

$ws->Run('cmd /c ' . $cmd, 0, false);


I tried:

[ul][li]with & without wscript.exe, cscript.exe, cmd /c, cmd.exe /c, cmd.exe /c /k[/li]
[li]referencing the path to the .vbs file with /, , and \[/li]

When I run the script from the command line it works perfectly.

The .vbs file is in a path outside the wwwroot folder. I set the permissions on the .vbs file & the folder it’s in to allow read & execute for the Internet Guest Account.

The web page seems to indicate the script is being executed but nothing happens. Process Explorer only shows the error: “[Error opening process]” but no other information.

Please help.

I made some changes trying psexec, but it still isn’t working. However, it runs perfectly from the command line. I think it’s gotta be close and it may have something to do with quoting/escaping double quotation marks or /'s or 's, but I don’t know what it’s looking for:

ini_set(‘display_errors’, ‘1’);

if($_POST[‘store_list’] && $_POST[‘start_date’] && $_POST[‘end_date’]){

echo 'processing<br><br>';

$cmd = 'psexec \\<> -u <username> -p <password> -e c:\windows\system32\cscript.exe c:\scripts\labor\scheduled\labor.vbs /store_list:"store1;store2" /start_date:"2013-01-21" /end_date:"2013-01-24"';

echo $cmd.'<br><br>';

$out = shell_exec($cmd);

echo '[' . $out.']<br><br>';
echo '<br>end';

echo ‘no data’;

I really can’t answer your question since I’ve never done this before. The only thing I can think of is that you should make sure the PHP user (typically this is the user ‘nobody’) has permission to execute this command.

Edit: Actually I’m thinking of linux whoops :slight_smile:

Hey, try using the direct path in your command line. I believe the issue is its looking for your exe file(s) in your php directory.


[php]exec(“c:\path\to\your\psexec.exe your prams”);[/php]

Let me know.

I tried putting in the full path to the file but it still didn’t work. I’ve determined that it’s some sort of permissions issue. I get this error when cscript.exe tries to run:

CScript Error: Loading your settings failed. (Access is denied. )

It’s running on iis Win 2008.

give this a shot.

hope it helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service