Solved

PHP Exec/System/Passthru/Shell_exec GPMC Scripts

Posted on 2011-03-19
6
607 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
  • 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 82

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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 and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now