Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Exec/System/Passthru/Shell_exec GPMC Scripts

Posted on 2011-03-19
6
Medium Priority
?
680 Views
Last Modified: 2012-06-27
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?
0
Comment
Question by:Vampireofdarkness
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 9

Author Comment

by:Vampireofdarkness
ID: 35172785
<?

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.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35172862
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.
0
 
LVL 9

Author Comment

by:Vampireofdarkness
ID: 35172930
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.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 9

Author Comment

by:Vampireofdarkness
ID: 35172932
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

0
 
LVL 9

Accepted Solution

by:
Vampireofdarkness earned 0 total points
ID: 35172976
Ok, I figured it out. I needed the /domain switch for the .wsf file. I had not included it previously. Stuck it on (domain.com, not just domain) and it works fine.

Thanks anyway.
0
 
LVL 9

Author Closing Comment

by:Vampireofdarkness
ID: 35205049
/domain switch required for the .wsf file
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question