Jump to content

how to run .vbs from php


raphael75

Recommended Posts

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:

 

 

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.

Edited by raphael75
Link to comment
Share on other sites

And what verifications have you done?

 

1. You say you have executed the script from a command prompt, but are you manually typing the string in or did you try the dynamically generated string? You are using variable in constructing that string so they may not contain what you think they do. The if() condition is only verifying that those POST variables exist - not that they actually have a value. Echo the command string to the page and then run THAT from the command line.

 

2. Is the path to the vbs file explicit (i.e. "C:\folder\") or relative (i.e. "\folder\")? If it is relative, it will need to be relative from the folder that the web server is running from (not the folder that the PHP file is executed from). At least this is what I found from my testing. So, in my XAMPP installation my path to the VBS file was relative from the root of the "xampp" root folder not the "htdocs" folder.

Edited by Psycho
Link to comment
Share on other sites

1. I tried both manually typing the command on the command line and pasting in the command line that the script is generating. Both work.

 

2. I was referencing the path to the script with an absolute path like:

 

c:\path\to\file\my_script.vbs

 

I also tried replacing the \'s with \\ and with /

 

 

 

 

 

And what verifications have you done?

 

1. You say you have executed the script from a command prompt, but are you manually typing the string in or did you try the dynamically generated string? You are using variable in constructing that string so they may not contain what you think they do. The if() condition is only verifying that those POST variables exist - not that they actually have a value. Echo the command string to the page and then run THAT from the command line.

 

2. Is the path to the vbs file explicit (i.e. "C:\folder\") or relative (i.e. "\folder\")? If it is relative, it will need to be relative from the folder that the web server is running from (not the folder that the PHP file is executed from). At least this is what I found from my testing. So, in my XAMPP installation my path to the VBS file was relative from the root of the "xampp" root folder not the "htdocs" folder.

Link to comment
Share on other sites

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:

 

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';
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.