Solved

PHP Exec/System/Passthru/Shell_exec GPMC Scripts

Posted on 2011-03-19
6
621 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now