0

I want to restart windows server remotely through the php script. But I am unable to do that.

I have created the .bat file on the windows server but I am unable to reach to that file remotely. I am using exec() function to do that using php

exec('c:\WINDOWS\system32\cmd.exe /c START C:\WINDOWS\abc.bat');
exec('shutdown -r -f -t 10 -m \\\\IP-ADDRESS -c "please wait system is rebooting"');
Jeff Zeitlin
  • 9,773
  • 2
  • 21
  • 33
Expinator
  • 21
  • 3
  • Is `abc.bat` on the _remote_ machine? The only way to get it to run on the remote machine is to execute a command on that machine. The first `exec()` will try to run a local script on the local machine. The second looks like it should restart the remote machine. What does `abc.bat` do? – mojo May 23 '19 at 13:20
  • `abc.bat` is used to restart a remote machine. that is on the remote machine. `exec('shutdown')` command is now working fine from my local machine but it's not working when I upload my code to my server. I am using ubantu server to upload the file – Expinator May 24 '19 at 05:45
  • Are _both_ machines (the "server" where the PHP is run and the "remote" machine you wish to reboot) running Windows? – mojo May 24 '19 at 13:10
  • no one is running ubantu and the other one is windows – Expinator May 27 '19 at 08:21
  • [This answer](https://stackoverflow.com/a/9937197/2092609) says how to issue a shutdown command from Linux. – mojo May 27 '19 at 12:51
  • The commands you've listed here will only work when run in Windows. They won't exist on Linux. – mojo May 27 '19 at 12:53

1 Answers1

0

for REBOOT

exec('shutdown /r');

To shut down your computer, type shutdown /s
To restart your computer, type shutdown /r
To log off your computer type shutdown /l
For a complete list of options type shutdown /?

with this commande you can run cmd under php.

exec('start cmd /k C:\WINDOWS\abc.bat');

OR

shell_exec('/s');
shell_exec('start cmd /k C:\WINDOWS\abc.bat');
Smar ts
  • 49
  • 5