Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Remote shutdown, hibernate and reboot your PC via Android


  • Please log in to reply
17 replies to this topic
quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
I got myself a Android device and I wanted a way to remotely reboot or shut down my PC at home.

This script runs on my PC 24/7 (Windows 7) and looks for the creation of a folder with a keyname. This folder is within another folder which is accessible via my FTP server. (I recommend the free and excellent FileZilla program)

So by using any free FTP App on my Tablet/phone I can hibernate, reboot or shutdown my PC.

Keyname words are :

Suspend
Shutdown
Reboot
Hibernate

(lettercase isn't important)

The script reads the specified folder every 10 secs and on seeing one of these keywords in a new folder it will perform the action within 30secs.

Alternatively, if you add "_XXX" to the folder name where XXX is the number of seconds (up to 999) it will perform the action with that delay.

Alternatively, if you use "_XXYY" where XXYY is the 24 hour clock format (ie 2305) it will perform that action at that time of day.

This script needs the free psshutdown.exe utility V2.52 by Microsoft/Sysinternals

<!-- m -->http://technet.micro... ... s/bb897541<!-- m -->

Just place the psshutdown.exe in a folder indicated by your PCs PATH variable.



#Persistent
#SingleInstance force
settimer, shutdown, 10000


SetTimer,UPDATEDSCRIPT,1000
; Alter this path to suit yourself.
; Remember it must be accessible via your FTP server
path:="Z:\Shutdown_reboot\"
return


shutdown:
;========================================================================
ifexist,%path%suspend*
{
flag=TRUE
 ps="-d"
loop,%path%suspend*,1
 {
 originalname:=A_LoopFileName
 break
 } 
 stringgetpos,offset,originalname,_
 if errorlevel
 {
 time:=25
 timemess:= "suspending in " . time . " seconds."
 } else
 { 
 stringmid,name,originalname,offset + 2,4
 stringlen,len,name
 if len =4 
 {
  stringleft,hour,name,2
  stringright,mins,name,2
  time:=hour . ":" . mins
  timemess:= "be suspending at " . time . " hours."
 } else
 {
 time:= name
 timemess:= "be suspending in " . time . " seconds."
 }
 }
}


;========================================================================
ifexist,%path%shutdown*
{
flag=TRUE
 ps="-k"
loop,%path%shutdown*,1
 {
 originalname:=A_LoopFileName
 break
 } 
 stringgetpos,offset,originalname,_
 if errorlevel
 {
 time:=25
 timemess:= "shut down in " . time . " seconds."
 } else
 { 
 stringmid,name,originalname,offset + 2,4
 stringlen,len,name
 if len =4 
 {
  stringleft,hour,name,2
  stringright,mins,name,2
  time:=hour . ":" . mins
  timemess:= "shut down at " . time . " hours."
 } else
 {
 time:= name
 timemess:= "be shutting down in " . time . " seconds."
 }
 }
}

;======================================================================== 
 ifexist,%path%reboot*
{
 flag=TRUE
 ps="-r"
 loop,%path%reboot*,1
 {
 originalname:=A_LoopFileName
 break
 } 
 stringgetpos,offset,originalname,_
 if errorlevel
 {
 time:=25
 timemess:= "reboot in " . time . " seconds."
 } else
 { 
 stringmid,name,originalname,offset + 2,4
 stringlen,len,name
 if len =4 
 {
  stringleft,hour,name,2
  stringright,mins,name,2
  time:=hour . ":" . mins
  timemess:= "reboot at " . time . " hours."
 } else
 {
 time:= name
 timemess:= "be rebooting in " . time . " seconds."

 }
 }
} 
;======================================================================== 
 
 ifexist,%path%hibernate*
{
flag=TRUE
ps="-h"
 loop,%path%hibernate*,1
 {
 originalname:=A_LoopFileName
 break
 }
 stringgetpos,offset,originalname,_
 if errorlevel
 {
 time:=25
 timemess:= "hibernate in " . time . " seconds."
 } else
 {
 stringmid,name,originalname,offset + 2,4
 stringlen,len,name
 if len =4 
 {
 stringleft,hour,name,2
 stringright,mins,name,2
 
 time:=hour . ":" . mins
 timemess:= "hibernate at " . time . " hours."
 } else
 {
 time:= name
 timemess:= "be hibernating in " . time . " seconds."
 }

 } 

}
 
 if flag = TRUE
 {
 FileRemoveDir,%path%%originalname%
 msgbox,,,This Computer will %timemess%,5
 Run, %comspec% /c "psshutdown %ps% -c -f -m "Remote Request to %timemess%" -t %time% -e p:01:01"
 flag=FALSE
 } 
return





;------------------------------------------------------------------------
UPDATEDSCRIPT:
FileGetAttrib,attribs,%A_ScriptFullPath%
IfInString,attribs,A
{
FileSetAttrib,-A,%A_ScriptFullPath%
SplashTextOn,,,Updating script...,
Sleep,500
Reload
}
Return
;ENDOFSCRIPT
;------------------------------------------------------------------------


Now I just need someone to make a Android App that can send a magic packet to my PC to wake it up!
Stuart Halliday

wooly_sammoth
  • Members
  • 644 posts
  • Last active: Jul 03 2013 08:08 PM
  • Joined: 12 May 2009
Search for WOL in the market place. There's various apps which can send magic packets.

There is also an app called unified remote which runs on your PC and can allow you to send mouse clicks, keyboard commands and power commands to your PC.

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
I built a secured website with a mySQL db on the back-end that holds a number of "functions" that I would like my PC to perform remotely, including reboot, shutdown, etc.

From ANY web-enabled device, I can log in to my site and select the function(s) I would like to have performed. My PC monitors a "results" page (via AHK script) and reacts to these requests, performing the specified function(s).

I think I'm going to have to "borrow" your idea of setting a delay... I hadn't bothered to do that, but think it's a good idea.

My PC never sleeps, so I don't need the WOL functionality, but it's not a bad idea and I'll have to investigate the concept a little further... I may need it down the road someday.

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005

Search for WOL in the market place. There's various apps which can send magic packets.

There is also an app called unified remote which runs on your PC and can allow you to send mouse clicks, keyboard commands and power commands to your PC.


Thanks.

I thought to search for magic packet. But not for WOL!

I've already got a VNC App. But this method I used is so much easier and faster to action.
Stuart Halliday

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
What I really want now is a mobile phone reset box to sit on my Cable modem or Wireless Router power.

As occasionally these devices freeze up.

Basically is anyone aware of a mobile phone that receives text messages and this message can be redirected to trigger a OFF/ON on a mains relay?

I remember last year having to travel 40 miles just to turn off/on a Router as it had locked up. Oh hum....
Stuart Halliday

..:: Free Radical ::..
  • Members
  • 74 posts
  • Last active: May 30 2015 12:13 PM
  • Joined: 20 Sep 2006
I made this using AHK

GMail Commander - Command Your PC Using GMail - <!-- m -->http://www.erodov.co... ... 38700.html<!-- m -->

I use this to remote control my pc using an email trigger from my symbian phone.

Should work with any device which can send an email though.

I am still working out why I get CDO transport failed errors sometimes.

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
On a related note...

<!-- m -->http://www.instructa... ... offee-Pot/<!-- m -->

..:: Free Radical ::..
  • Members
  • 74 posts
  • Last active: May 30 2015 12:13 PM
  • Joined: 20 Sep 2006
I have posted the source code for my app in a fresh thread.

<!-- m -->http://www.autohotke...pic.php?t=67120<!-- m -->

You are free to modify and improve on it :)

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005
Nice. But in most cases you need to remove the power from a device to get it to reboot correctly.

PCs, etc. keep power to the motherboard even when powered down so the only way to do a hard reset to the electronics is to pull the plug.


One method I'd thought of was a sound detector wired to a cheapo Nokia phone via its data connector. On hearing a specific tone from the phone the box would remove the Mains for 30secs.
Stuart Halliday

zzzooo10
  • Members
  • 237 posts
  • Last active: Apr 14 2015 01:57 AM
  • Joined: 19 Dec 2010
quatermass

What app on android did you use and how to did you get your phone to connect to your ftp sever?

wtg
  • Members
  • 251 posts
  • Last active: Dec 19 2012 03:54 PM
  • Joined: 04 Oct 2006

Nice. But in most cases you need to remove the power from a device to get it to reboot correctly.

One method I'd thought of was a sound detector wired to a cheapo Nokia phone via its data connector. On hearing a specific tone from the phone the box would remove the Mains for 30secs.


I'm not sure that I'd agree with your in most cases statement, but sometimes you do need to cut the power. I have an external device used to record stuff from my cable box that needs an occasional hard reset and I do this from the PC via an X10 control module. X10 modules work well for controlling lights and other things too, whether via remote, programmable control modules or PC.

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005

quatermass

What app on android did you use and how to did you get your phone to connect to your ftp sever?


I just use andFTP but any decent FTP Android App will do it like ES File Explorer.
Stuart Halliday

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005

I'm not sure that I'd agree with your in most cases statement, but sometimes you do need to cut the power. I have an external device used to record stuff from my cable box that needs an occasional hard reset and I do this from the PC via an X10 control module. X10 modules work well for controlling lights and other things too, whether via remote, programmable control modules or PC.


I did find a X10 home automation controller that plugs into the telephone socket, so you can can use it to ring up and switch items off/on.
But no one sells I think a controller that uses mobile phones, they all use a landline.

Thanks for pointing out X10 devices to me. :)
Stuart Halliday

wtg
  • Members
  • 251 posts
  • Last active: Dec 19 2012 03:54 PM
  • Joined: 04 Oct 2006
No, but via the PC you can tell the controller to cut the power off to a device - even the PCs power - and turn it back on in a minute. There are any number of ways to kick off that process on the PC via your phone.

quatermass
  • Members
  • 220 posts
  • Last active: Dec 16 2013 09:00 PM
  • Joined: 14 Dec 2005

No, but via the PC you can tell the controller to cut the power off to a device - even the PCs power - and turn it back on in a minute. There are any number of ways to kick off that process on the PC via your phone.


Assuming the PC or the Router is working?

I've had cases were the Router goes dead and I've had to drive in and just turn it off/on again. As a typical IT guy I want to save me that journey for something so trivial. :)

In a Server Farm you can request a manual hard reset. But as this involves a person, you have a queue and time factor. It also costs.

Just would be nice to automate it.
Stuart Halliday