0

I'm running phpvirtualbox-5.0-4 on my WAMP testing server. I would like to run the following batch file from a php script....need so to open Windows 7 command prompt with admin privileges (preferably in background mode)

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

Thanks for any answer.

Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
  • http://stackoverflow.com/questions/14680605/exec-not-working-in-php-script-wamp-server have you tried this one (and I suggest running WAMP as administrator as well)? – online Thomas Jan 06 '16 at 16:04
  • Possible duplicate of [How can I run several PHP scripts from within a PHP script (like a batch file)?](http://stackoverflow.com/questions/894390/how-can-i-run-several-php-scripts-from-within-a-php-script-like-a-batch-file) – Vidya Sagar Jan 06 '16 at 16:11

3 Answers3

0

You will need something to kick the script off (like a CRON job).

But you should use the shell command as follows:

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

From the documentation, please be aware:

Note:
This function is disabled when PHP is running in safe mode.
Sablefoste
  • 4,032
  • 3
  • 37
  • 58
0

Got it !!!!

$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>";

And my batch file:

@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 !!!

0
shell_exec()

should work but for it to work, the apache server must have administrative privileges itself to execute it. Simply put, you have to start the apache server as an administrator. (In windows, run as administrator option). Then all exec() commands in PHP will have administrative privileges.

Vimukthi Sineth
  • 310
  • 2
  • 8