0

I want to remote shutdown computer that have same network with me, in cmd.exe we can execute this to do that

shutdown /m \\192.168.1.2 /s /f /c 'PC will shutdown in 5 seconds' /t 5

but i have tried with php command exec() and it didn't do anything. I put the php command in shutdown.php

exec("shutdown /m \\192.168.1.2 /s /f /c 'PC will shutdown in 5 seconds' /t 5");

1 Answers1

0

try this. in place of username, put administrator username and password. put the domain if exists. then put the name of bat file there. the bat file would contain the shutdown command. also try directly putting the command there.

runas /U username /P password /D Domain /E shutdown.bat

Researched from the community, found this helpful

First up, just to let you know that you're trying to reinvent the wheel. What you're really looking for is expect(1), which is a command-line utility intended to do exactly what you want without involving PHP.

However, if you really want to write your own PHP code you need to use proc_open. Here are some good code examples on reading from STDOUT and writing to STDIN of the child process using proc_open:

http://www.php.net/manual/en/function.proc-open.php#79665 How to pass variables as stdin into command line from PHP http://camposer-techie.blogspot.com/2010/08/ejecutando-comandos-sobre-un-programa.html (this one is in Spanish, sorry, but the code is good) Finally, there is also an Expect PECL module for PHP.

Hope this helps.

source : PHP Exec command - How to pass input to a series of questions

Yash Kumar Verma
  • 9,427
  • 2
  • 17
  • 28