![]() |
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:
Code:
error_reporting(E_ALL);I tried:
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. |
What is it you're expecting the vbs script to do? Looking at this, there isn't a way to determine what the .vbs has done, so unless you're logging something than it'll be hard to determine what is happening. The COM is a pain since it's marshaled across directly, so you can't do things like error handling using PHP without implementing all the necessary logic.
Not sure what vbs has the capability of doing, but you should start by adding a logging feature. You should be able to flag the run command as well to change the windowed mode (the 0 is hidden), but I'm not 100% sure if it'll remain open. To me it look like it needs a '5' as the option, which MS indicates would do: Quote:
|
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:
PHP Code:
|
Yep, that's always a catcher. I don't see it here, but it doesn't mean it doesn't exist.
I see you printed the $cmd here, so that's a good start. Drag that up from the HTML source itself (not from the browser window), and paste that into the command line. If that's good, we can look at the next step. Does it ever make it to the echo that indicates the end and the $out, or does it just hang there and timeout eventually? |
An alternate suggestion:
Execute a ".bat" file and have that ".bat" file contain the command. If need be, PHP can create the ".bat" file. The advantage is that you can actually then LOOK at the ".bat" file to see if it contains what you expect it to contain *and* you can execute it by hand to make sure it works when you do so. I have even done this when invoking ".vbs" from other ".vbs" code. Just so I can be sure that I'm issuing the command I think I'm issuing. |
Quote:
CScript Error: Loading your settings failed. (Access is denied. ) |
Quote:
One thing to test, is on the command line launch the PHP directly by executing php -f /path/to/your/php/script.php, and seeing what that does. That should use your user credentials to execute the php script which in turn should use the same credentials when launching the shell_exec.Try that and let us know how it turns out. I like the bat idea as well, simple and central. |
Quote:
PHP Code:
nt authority/iusr I did some research (http://forums.iis.net/t/1147103.aspx) on that and it appears that "nt authority/iusr" replaced the anonymous IIS user in win 2008. Also, the permissions for it aren't configured the same way as a normal user. I don't know what to do next. Any help will be greatly appreciated! |
Yep, kinda sounded like a privilege issue. I remember how much of a pain it was configuring the 2003 machines with IIS, and I haven't looked back since :P
Take a look at this one: http://www.iis-aid.com/articles/trou...unable_to_fork which indicates to modify the acl for the IIS user. I'm not sure if I like that approach, but I think it beats executing it as another user with more access. |
Quote:
I also found several pages that said to create these registry keys: HKEY_USERS\.DEFAULT\Software\Microsoft\Windows Scripting Hostand set the permissions to allow EVERYONE Read access, which I did. Doing those things made the CScript Error: Loading your settings failed. (Access is denied. )error go away, but the batch file still won't execute. The batch file now contains a line like this: Code:
c:\scripts\labor\scheduled\cscript.exe //B c:\scripts\labor\scheduled\labor.vbs /store_list:"store1;store2" /start_date:"2013-01-21" /end_date:"2013-01-24"PHP Code:
"nt authority/iusr" (shows up as iusr) Do you have any more ideas? :) |
So here's where it is now:
I can create the batch file. The batch file runs perfectly when I run it from the command line. When I run PHP Code:
Why does it just echo back the contents of the batch file without executing it? Thanks!! |
| All times are GMT +1. The time now is 06:59 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.