2016-01-06 50 views
0

我在我的WAMP测试服务器上运行phpvirtualbox-5.0-4。 我想运行PHP脚本中下面的批处理文件....需要这么打开Windows 7的命令提示符下使用管理员权限(最好是在后台模式)如何使用管理员权限从php脚本中打开批处理文件

cd/
cd C:\Program Files\Oracle\VirtualBox 
Vboxmanage setproperty websrvauthlibrary null 
Vboxwebsrv.exe >null 

感谢您的任何答复。

+0

http://stackoverflow.com/questions/14680605/exec-not-working-in-php-script- wamp-server你有没有试过这个(我建议以管理员身份运行WAMP)? –

+0

[我怎样才能从一个PHP脚本(如批处理文件)运行几个PHP脚本?](http://stackoverflow.com/questions/894390/how-can-i-run-several-php-脚本由内而外地-A-PHP脚本样一个批处理文件) –

回答

0

您需要一些东西来踢脚本(如CRON作业)。

但是,你应该按如下方式使用shellcommand

echo shell_exec("cd C:\Program Files\Oracle\VirtualBox Vboxmanage 
       setproperty websrvauthlibrary null Vboxwebsrv.exe >null"); 

从文档,请注意:

Note: 
This function is disabled when PHP is running in safe mode. 
0

明白了!!!!

$test = shell_exec('C:\\WINDOWS\\system32\\cmd.exe /c 2>&1 "H:\\wamp\\www\\sito2\\files batch\\fare partire phpVirtualBox.bat"'); 
echo "<pre>$test</pre>"; 

我的批处理文件:

@ECHO OFF 
::Test If script has Admin Priviledges/is elevated 
AT > NUL 
IF %ERRORLEVEL% EQU 0 (
    ECHO OK ! Command prompt launched...you are Administrator ! 
) ELSE (
    ECHO you are NOT Administrator. Exiting... 
    PING 127.0.0.1 > NUL 2>&1 
    EXIT /B 1 
) 
cd/
cd C:\Program Files\Oracle\VirtualBox\Vboxmanage setproperty websrvauthlibrary null 
C:\Program Files\Oracle\VirtualBox\Vboxwebsrv.exe >null 

the result !!!

相关问题