Php to run / start batch file on host (server)

Hallo forum

I need some help to start a .bat file on my server, when i click on a button on my web page…

I have tried

exec (bat.bat)
exec(“cmd.exe /c bat.bat”)
system(bat.bat)
system(“cmd /c C:\inetpub\www.kekec.dk\include\bat.bat”)

My bat file conatins (only for test purpose)

@ECHO off
echo Hallo
ipconfig
start c:windows/notepad.exe
pause

what my main purpose is:
Restart pc
Run some cmd (start some app./service/backup etc.)

Please advise

This is the right one.

notepad path is invalid (missing /)

hmm invalid?
When i copy paste c:windows\notepad.exe in run.exe and when i run the batch normaly from windows 8.1 it has no problems to open notepad…

hmm something else is wrong?

Im runing iis 8.5 (windows 8.1) with anonymous aut. (here’s is specified user - admin)
and i created a test.bat file that only opens explorer like this:
%SystemRoot%\explorer.exe

and when i try to open it with my test.php:

system(‘c:\WINDOWS\system32\cmd.exe /c C:\inetpub\www.kekec.dk\include\test.bat’);
system(‘test.bat’);

exec(‘c:\WINDOWS\system32\cmd.exe /c C:\inetpub\www.kekec.dk\include\test.bat’);
exec(‘test.bat’);

shell_exec(“C:\windows\system32\cmd.exe /c test.bat”);
shell_exec(‘test.bat’);

none of them opens exlporer - ONLY outputs :
C:\inetpub\www.kekec.dk\include>C:\Windows\explorer.exe

please advise

  • edit my test.php and test.bat is in the same dir.
Sponsor our Newsletter | Privacy Policy | Terms of Service