Remotely Suspend or Resume Windows 10 PC from Linux

All kinds of 'OS' scripts
Post Reply
Posts: 538
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta

Remotely Suspend or Resume Windows 10 PC from Linux

Post by ben53252642 » Sunday 15 July 2018 3:06

Script I'm using to suspend / sleep my Windows 10 desktop PC from Linux and resume / wake it on demand.

Example usage from bash terminal:
./ "wake"
./ "sleep"

1) apt-get install etherwake sshpass fping
2) Make sure Wake on LAN is enabled in the PC's BIOS
3) Setup OpenSSH server on the Windows 10 PC.

Code: Select all


# Windows 10 PC Configuration

# Send WOL packet to PC (and repeat for up to 10 seconds if unable to ping the IP)
if [[ $1 == 'wake' ]]; then
wakeonlan "$mac" && timeout 10 bash -c -- "until fping -c1 -b 32 -t1000 $ip &>/dev/null; do wakeonlan $mac ; done"

elif [[ $1 == 'sleep' ]]; then
timeout 5s sshpass -p "$password" ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=no "$username"@"$ip" 'powercfg -h off & rundll32.exe powrprof.dll,SetSuspendState 0,1,0'

Example Lua device script:

Code: Select all

commandArray = {}

if (devicechanged["Desktop PC"] == 'On') then
os.execute ("/root/scripts/pcpowercontrol/ 'wake' &")

return commandArray
Useful Windows commands (run in cmd)
  • See last device to wake the pc: powercfg -lastwake
  • See list of devices allowed to wake the pc: powercfg -devicequery wake_armed
  • Disable a device from being allowed to wake the pc: powercfg -devicedisablewake "DEVICE_NAME"

1) The command disables Windows 10 hibernation before issuing the sleep command (I want the Windows 10 PC to sleep, not hibernate)
2) SSH certificate verification is disabled which may be a security concern in some situations. You can easily enable it by changing "StrictHostKeyChecking=no" to "StrictHostKeyChecking=yes"

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests