Run powershell in php
I have a very small program which I want to execute upon button press . In html it contains an button with an image and when i press the button it should call my php script which has powershell and has to be executed . But it doesnt add the printer through the manual command attached is working.
My html code here is as follows :
<html> <head> <form action="rabbit.php" method="POST"> <input type="image" src="image/GOOGLE.jpg" value="submit" alt="Submit" width="78" height="78"> </head> </html>
Php code :
<?php echo powershell.exe (New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\\file-computer-01\IN-SEA-GOOGLE"); ?>
Even I tried in this way and it just echo's the command :
<?php $psPath = 'c:\\Windows\\System32\WindowsPowerShell\v1.0\\powershell.exe'; $psDIR = "c:\\wamp\\www\\printer\\scripts\\"; $psScript = "rabbit.ps1"; $runScript = $psDIR. $psScript; $runCMD = $psPath. "&". $runScript; echo $runCMD; ?>
Moreover I get the output as in the page as :
My powershell code contains like this :
(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection("\\file-computer-01\IN-SEA-GOOGLE")
If I execute the direct powershell script it works but not via PHP .
In both the cases, it just gives echo and doesnt add the printer .
Any ideas or suggestions please.... as i new to php struggling a lot to figure it out this.