Link to home
Start Free TrialLog in
Avatar of Vampireofdarkness
VampireofdarknessFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PHP Exec/System/Passthru/Shell_exec GPMC Scripts

I'm looking to make a small intranet-based web application that builds on the GPMC Scripts of Server 2003 (%programfiles\GPMC\Scripts\).

I have a .bat file that works absolutely fine and does what I want it to do; however, if I call the .bat file from within PHP (either system("test.bat"), exec, etc...) the expected output does not happen.

I've tried calling a basic function from within a .bat
cscript "%programfiles%\GPMC\Scripts\GetReportsForAllGPOs.wsf" C:\reports

Open in new window

which works from the .bat, but not from PHP.

I've tried:
  1. escaping the \s, in case that was causing problems
  2. using both %programfiles% and C:\Program Files\
  3. with and without cscript
  4. with and without cmd /c, or /k or /d

No go. It does output the first line of the .wsf file ("Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. ") but nothing called after that happens.

Any ideas?! Is this even possible?
Avatar of Vampireofdarkness
Vampireofdarkness
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

<?

exec("cscript \"C:\\Program Files\\GPMC\\Scripts\\GetReportsForAllGPOs.wsf\" C:\\reports",$output,$error);

var_dump($output);
var_dump($error);

?>

Open in new window


produces

array(3) { [0]=> string(45) "Microsoft (R) Windows Script Host Version 5.6" [1]=> string(67) "Copyright (C) Microsoft Corporation 1996-2001. All rights reserved." [2]=> string(0) "" }

int(0) 

Open in new window


Using \ instead of \\ in the script path and/or output changes nothing.

If I add "cmd /k" before "cscript", in order to keep it alive after execution, the $output is now
array(5) { [0]=> string(45) "Microsoft (R) Windows Script Host Version 5.6" [1]=> string(67) "Copyright (C) Microsoft Corporation 1996-2001. All rights reserved." [2]=> string(0) "" [3]=> string(0) "" [4]=> string(15) "C:\AppServ\www>" }

Open in new window

which would imply it has completed as it has returned to a blank line.

If I remove cscript and just use "cmd /k \"C:\....wsf\" ..." the script hangs. No output returned, nothing in C:\reports.
Avatar of Dave Baldwin
Are you running it from the command line or thru the webserver?  On the command line, it runs under your permissions.  Thru the web server, it runs with minimal permissions.
Command line works fine. Through apache/PHP it does not and I cannot use runas as a workaround as it doesn't accept a piped password as well as the /savecred switch not appearing to function as it perhaps should -- /savecred works for the .bat, but not when calling from PHP.
Also, I haven't tested this yet as a workaround for runas not accepting piped passwords: http://www.tek-tips.com/faqs.cfm?fid=2760

ASKER CERTIFIED SOLUTION
Avatar of Vampireofdarkness
Vampireofdarkness
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
/domain switch required for the .wsf file