how to run .vbs from php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

how to run .vbs from php

Postby raphael75 » Tue Jan 29, 2013 10:30 am

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:

Code: Select all

error_reporting(E_ALL);
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:
    with & without wscript.exe, cscript.exe, cmd /c, cmd.exe /c, cmd.exe /c /k
    referencing the path to the .vbs file with /, \, and \\
    exec()
    shell_exec()

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.

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: how to run .vbs from php

Postby raphael75 » Wed Jan 30, 2013 12:45 pm

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:

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');

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

   echo 'processing<br><br>';
   
   $cmd = 'psexec \\<computername.domainname.com> -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';
   
}
else{
   echo 'no data';
}

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: how to run .vbs from php

Postby raphael75 » Thu Jan 31, 2013 5:32 am

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.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: how to run .vbs from php

Postby seandisanti » Thu Feb 07, 2013 4:56 pm

You may have better luck getting help on that one on an IIS forum, or maybe you could just mirror the functionality of the .vbs script with your php code and not need to run external scripts...


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest