简体   繁体   English

在Windows 8.1中通过exec()执行具有管理员权限的批处理脚本

[英]Execute batch script with admin rights in windows 8.1 by exec()

I am trying to run a batch file from php with exec() but it is not working. 我正在尝试使用exec()从php运行一个批处理文件,但是它不起作用。 When I run the same script in a command window in admin mode the script works. 当我在admin模式下的命令窗口中运行相同的脚本时,该脚本有效。

Now I want to know how can I configure in php that my script can be execute with ADMIN mode. 现在,我想知道如何在php中配置我的脚本可以在ADMIN模式下执行。

You can use RunAs Command . 您可以使用RunAs Command Since it will ask admin password and you are running it from web you should pipe the admin password to the command. 由于它将询问管理员密码,并且您正在通过Web运行它,因此应将管理员密码传递给命令。

exec('echo adminpassword | runas /user:administrator fullPathToProgram',$output);
print_r($output);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM