Remote shutdown

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mirainc
    New Member
    • Jul 2008
    • 34

    Remote shutdown

    Hi all,

    I want to do a remote shutdown to PC that is in the same domain as mine. I managed to do a command prompt version and it works but now i need to add it in my application, so i tried converting it to PHP, but i cannot seem to get the result i want. Can anyone tell me what i am doing wrong..

    In CMD:
    c:\WINDOWS\Powe r\psshutdown.ex e \\172.16.223.21 3 -u sadmin -p studadmin -f -k -t 1

    In PHP:
    [PHP]
    if (isset($_POST['Rshutdown']) && ($_POST['Rshutdown'] == 'Shutdown'))
    {
    $ipaddress = (' \\\\' .$_POST['Ripadd']);
    $username = (' -u ' .$_POST['Rname']);
    $userpw = (' -p ' .$_POST['Rpw']);
    $shutdownMins = (' -t ' .$_POST['Rmins']);
    $all = (($ipaddress) .($username) .($userpw));
    $remoteshutdown = ('c:\windows\po wer\psshutdown. exe' .($all) .' -f -r' .($shutdownMins ));
    echo "$remoteshutdow n";
    $a = shell_exec($rem oteshutdown);
    }
    [/PHP]

    Thanks in advance..
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    when you do that echo there, is the output correct?

    if so, it may be some kind of weird permission problem I think.

    shell_exec() should work.

    something else you can do is capture the output, send it to a file for example: command > test.txt

    sends the output of "command" to test.txt in your working directory.


    Good luck,


    Dan

    Comment

    • mirainc
      New Member
      • Jul 2008
      • 34

      #3
      hi Dan,
      Yes the echo output is correct but i cannot figure out why it does not execute in cmd.. any other way to execute the command in cmd? besides shell_exec() because its still not working.

      Thanks

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Try simply echoing the output of the shell_exec function. See if that returns anything useful.

        Another thing... is it possible that there is a space missing between "psshutdown.exe " and the following parameters?

        Comment

        • mirainc
          New Member
          • Jul 2008
          • 34

          #5
          Originally posted by Atli
          Try simply echoing the output of the shell_exec function. See if that returns anything useful.

          Another thing... is it possible that there is a space missing between "psshutdown.exe " and the following parameters?

          Ok. Actually when i echo "$remoteshutdow n"; the output i get is:
          c:\WINDOWS\Powe r\psshutdown.ex e \\172.16.223.21 3 -u sadmin -p studadmin -f -r -t 60

          so i actually copied n pasted tat echo line into cmd and it works. So now i donno why the shell_exec() won't execute the line.

          When i echo the shell_exec() function i get nothing. but if i don input any values i get the options for psshutdown (like, the different commands that shutdown, restart etc..) but when i input the ipaddress, username, pw n time nothing happens.

          Comment

          Working...