0

Does anyone have an idea on how I can execute the below code in php ?

 <?php
  $output = "rundll32 printui.dll PrintUIEntry /in /n \\omgb-omga-1\printer-hr";
 ?>

Running the above doesn't add the network printer...

Does my syntax in php is correct ? Because I am able to add the printer when i paste the command in command prompt .

user3111077
  • 13
  • 1
  • 4

1 Answers1

0

Use exec() (note that it may need to add the full path to rundll32.exe) :

$output = array();
exec("C:\\Windows\\system32\\rundll32.exe PrintUIEntry /in /n \\\\omgb-omga-1\\printer-hr", $output);
var_dump($output);

According to this answer, backslashes should be escaped (which I did in my example), but I'm not sure if it's needed for the command's arguments.

Note that exec() only returns the last line returned by the command; to get the entire output you need to use a separate array (here $output) that will be filled with the command's output.

Community
  • 1
  • 1
  • I tried on what you said and here is what in my php code its now and still i dont see it gets added . No errors I can see on the page – user3111077 Dec 28 '13 at 10:33
  • I think when i run the code which i given in my first reply it just adds the printer and don't get any output in command prompt. so i executed in the way you told and here is what i get in webpage: "array (size=0) empty" does that make sense ? "c:\windows\system32\rundll32 printui.dll PrintUIEntry /in /n \\omgb-omga-1\printer-hr" adds the printer without any issues... this is the same command i want to execute upon a button press... but this doesnt seems to be working... please let me know if i am wrong in something – user3111077 Dec 28 '13 at 10:55