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 .
Use exec() (note that it may need to add the full path to
rundll32.exe
) :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.