Solved

PHP Exec/System/Passthru/Shell_exec GPMC Scripts

Posted on 2011-03-19
6
628 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 83

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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

815 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

8 Experts available now in Live!

Get 1:1 Help Now