PHP execution for rundll

743 views Asked by At

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 .

1

There are 1 answers

2
AudioBubble On

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.