PHP execution for rundll

好久不见. 提交于 2019-12-11 16:31:16

问题


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:


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.



来源:https://stackoverflow.com/questions/20813259/php-execution-for-rundll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!