PHP执行Rundll [英] PHP execution for rundll
问题描述
有人对我如何在php中执行以下代码有想法吗?
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...
我在php中的语法正确吗?因为我可以在将命令粘贴到命令提示符时添加打印机.
Does my syntax in php is correct ? Because I am able to add the printer when i paste the command in command prompt .
推荐答案
使用 exec()(请注意,可能需要将完整路径添加到rundll32.exe
):
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.
请注意,exec()
仅返回命令返回的最后一行;要获得整个输出,您需要使用一个单独的数组(此处为$output
),该数组将填充命令的输出.
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.
这篇关于PHP执行Rundll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!