Run and complete command when sleep is triggered?


Futurdreamz

Active member
Member
Local time
11:07 AM
Posts
122
OS
Windows 11
My setup requires me to manually turn my speakers on and off, I want to automate that.

I got a smart plug, installed python, and the python program that controls the plug

so I can now run a bat file with the line of kasa --alias "speakerplug" off to turn the speakers off, and "...on" to turn on.

When the computer starts or I login, and the computer wakes from sleep: I want the command to turn the speakers on to run
When the computer shuts down and sleeps: i want the command that turns the speakers off to run

I'm finding solutions for each condition, except when I want the command to run when sleep is initiated. I want the computer to be put to sleep by any normal means and turn off the speakers when doing so,

There seems to be a program that only works for Windows XP era systems and doesn't work, and there seems to be a Windows 7 era program, but all download links are broken.

How do I run a command that is automatically triggered when the computer starts to go to sleep, and completes running before the computer goes to sleep?
 

My Computers My Computers

  • At a glance

    Windows 11AMD Ryzen 5 3600G.Skill Flare X 16 GB (2 x 8 GB) DDR4-3200 CL...Dell OEM RX 5700
    OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    "Selene"
    CPU
    AMD Ryzen 5 3600
    Motherboard
    Gigabyte A520I AC Mini ITX AM4
    Memory
    G.Skill Flare X 16 GB (2 x 8 GB) DDR4-3200 CL16 Memory
    Graphics Card(s)
    Dell OEM RX 5700
    Monitor(s) Displays
    LG 29UM69G-B 29.0" 1.5X Ultrawide 75 Hz Monitor
    Screen Resolution
    2560 x 1080
    Hard Drives
    Intel 660p 1.02 TB M.2-2280 PCIe 3.0 X4 NVME Solid State Drive
    Western Digital Caviar Blue 1 TB 3.5" 7200 RPM Internal Hard Drive
    PSU
    Corsair CX650M 650 W 80+ Bronze Certified Semi-modular ATX Power Supply
    Case
    Thermaltake Suppressor F1
    Keyboard
    SteelSeries APEX RGB Wired Gaming Keyboard
    Mouse
    SteelSeries Rival 300 Wired Optical Mouse
    Other Info
    SteelSeries Arctis 5 7.1 Channel Headset
  • At a glance

    Windows 11
    Operating System
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    MSI Katana GF76 11 UD

My Computer My Computer

At a glance

Windows 11, Windows 10, Linux Fedora Cinnamon
OS
Windows 11, Windows 10, Linux Fedora Cinnamon
The OP has also asked this question in Run command BEFORE going to sleep?- TenForums
I think that both OSes behave in the same way and I do not think there is any EventViewer-based solution for running a script before sleeping.

Isn't the turn on script after start/restart/wake from sleep/wake from hibernation sufficient?
Might a combined turn off then turn on script after start/restart/wake from sleep/wake from hibernation be sufficient?


Denis
 

My Computer My Computer

At a glance

Windows 11 Home x64 Version 25H2 Build 26200....
OS
Windows 11 Home x64 Version 25H2 Build 26200.8037
RE: "there seems to be a Windows 7 era program, but all download links are broken".
JFI: "Windows 7 Suspend/Resume Control" is available within the following Codeplex archive, but I have no idea whether it works as desired in Windows 11 or not.


Search for this specific project zip on that page: win7suspendresume.zip

The win7suspendresume.zip project contains the Releases folder with 4 zipped releases, with "49d2ea10-7a2a-4265-81b0-0d8f3eb00d24" being the last one.

That "49d2ea10-7a2a-4265-81b0-0d8f3eb00d24" contains an setup.exe together with an setup.msi file.

Code:
"Name": "Version 2.0.0.1",
"ModifiedDate": "2013-02-05T08:19:15.957-08:00",       ***
"49d2ea10-7a2a-4265-81b0-0d8f3eb00d24",                ***

pn: Unfortunately, whilst on my VirtualBox Win11 virtual machine, I could install the software/service, the issues I had were :
a) There is no way to trigger a proper sleep/suspend/resume in VirtualBox, so couldn't test any further.
b) All the Program tabs were populated in accordance with what was running in the machine, except the Devices tab which threw the Fault shown (Issue was reported with Windows 10 so presumably the other functions worked in Win10 (?)).

So experiment with caution on a real Win11 machine.

PowerTriggers 2.pngPowerTriggersService.png
 

My Computer My Computer

At a glance

Win 11 25H2intel i7-870032GbIntel iGPU
OS
Win 11 25H2
Computer type
PC/Desktop
Manufacturer/Model
custom
CPU
intel i7-8700
Motherboard
Asus Z370 TUF Gaming
Memory
32Gb
Graphics Card(s)
Intel iGPU
Sound Card
Realtek
Hard Drives
Samsung
PSU
Corsair
Cooling
Fans
RE: "there seems to be a Windows 7 era program, but all download links are broken".
JFI: "Windows 7 Suspend/Resume Control" is available within the following Codeplex archive, but I have no idea whether it works as desired in Windows 11 or not.


Search for this specific project zip on that page: win7suspendresume.zip

The win7suspendresume.zip project contains the Releases folder with 4 zipped releases, with "49d2ea10-7a2a-4265-81b0-0d8f3eb00d24" being the last one.

That "49d2ea10-7a2a-4265-81b0-0d8f3eb00d24" contains an setup.exe together with an setup.msi file.

Code:
"Name": "Version 2.0.0.1",
"ModifiedDate": "2013-02-05T08:19:15.957-08:00",       ***
"49d2ea10-7a2a-4265-81b0-0d8f3eb00d24",                ***

pn: Unfortunately, whilst on my VirtualBox Win11 virtual machine, I could install the software/service, the issues I had were :
a) There is no way to trigger a proper sleep/suspend/resume in VirtualBox, so couldn't test any further.
b) All the Program tabs were populated in accordance with what was running in the machine, except the Devices tab which threw the Fault shown (Issue was reported with Windows 10 so presumably the other functions worked in Win10 (?)).

So experiment with caution on a real Win11 machine.

View attachment 67168View attachment 67169
thank you, that program worked. I just wasn't able to find a download. When looking they said that version 1.0.1 is recommended as the version 2 rewrite had bugs so I installed 1.0.1 and it works fine, just had to add it to startup items

this would be nice as a PowerToy feature though
 

My Computers My Computers

  • At a glance

    Windows 11AMD Ryzen 5 3600G.Skill Flare X 16 GB (2 x 8 GB) DDR4-3200 CL...Dell OEM RX 5700
    OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    "Selene"
    CPU
    AMD Ryzen 5 3600
    Motherboard
    Gigabyte A520I AC Mini ITX AM4
    Memory
    G.Skill Flare X 16 GB (2 x 8 GB) DDR4-3200 CL16 Memory
    Graphics Card(s)
    Dell OEM RX 5700
    Monitor(s) Displays
    LG 29UM69G-B 29.0" 1.5X Ultrawide 75 Hz Monitor
    Screen Resolution
    2560 x 1080
    Hard Drives
    Intel 660p 1.02 TB M.2-2280 PCIe 3.0 X4 NVME Solid State Drive
    Western Digital Caviar Blue 1 TB 3.5" 7200 RPM Internal Hard Drive
    PSU
    Corsair CX650M 650 W 80+ Bronze Certified Semi-modular ATX Power Supply
    Case
    Thermaltake Suppressor F1
    Keyboard
    SteelSeries APEX RGB Wired Gaming Keyboard
    Mouse
    SteelSeries Rival 300 Wired Optical Mouse
    Other Info
    SteelSeries Arctis 5 7.1 Channel Headset
  • At a glance

    Windows 11
    Operating System
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    MSI Katana GF76 11 UD

Latest Support Threads

Back
Top Bottom