Scheduling a script (network-connected) to run when system goes into sleep/standby


pranavAbe

Member
Local time
9:29 AM
Posts
2
Location
Stuttgart, Germany
OS
Windows 11
Hello đź‘‹


I've been having some trouble with a PowerShell script I've been scheduling through the Task Scheduler to run and invoke a Python script that's meant to turn off some smart lights when my laptop goes into a sleep state. The task watches for Event 506 from the Kernel-Power source of the System logs (this event records when the system transitions to the S0 Modern Standby state), and triggers accordingly; but the issue I'm facing is that since the script requires network connectivity, it fails to execute the required commands until the system returns to an active state.

Additionally, I've rounded it down to being a network connectivity issue, since when the action for the task is just to log the time instead, it logs exactly a few seconds after the system switches to standby, as it should. But on the contrary, the moment the script requires network connectivity (I set the action to log the time and ping a website), it will only run when the system transitions back to an "awake" state.

The task is configured to run whether the user is logged in or not, run with the highest privileges, and to wake the computer to run the task, and to aid that, I've also turned on allow wake timers, and network connectivity in standby from the advanced power plan settings in the Control Panel, but it's all been to no avail.

If there's something I'm missing here in task scheduling setup, or if there's any other workarounds that'll help me achieve what I'm looking to do, I'm all ears.


> I've attached a copy of the task I'm running along (TestTask.txt - please change the file format to XML. I can't seem to upload the XML file as it is restricted by the forum) with a basic script for the time and ping logging (LogTimeAndPing.ps1). You will have to modify the folder locations within the script and within the task. Feel free to import it into Task Scheduler yourself, make the necessary changes, and suggest a solution if you've got one.
 
Windows Build/Version
Version 24H2 (Build 26120.1524)

Attachments

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Asus ZenBook Duo (UX8406MA)
    CPU
    Intel Core Ultra 9 185H
    Memory
    32 GB
    Graphics Card(s)
    Intel Arc (Meteor Lake-P)
    Hard Drives
    WD SN560 (1 TB)
    Mouse
    Asus Rog Chakram X Origin
From Device Manager, you should confirm if the interface's per-device Power Management setting isn't set to Selective Suspend.
 
Last edited:

My Computer

System One

  • OS
    Windows 7
From Device Manager, you should confirm if the interface's per-device Power Management setting isn't set to Selective Suspend.
I've checked the Selective Suspend settings, and they're configured to be disabled while plugged in. This still doesn't resolve my problem.

Additionally, while doing this, I also came across someone suggesting changing the power management settings for my Wi-Fi card, and changing this to disable the computer to change the power state of the card, kept causing my system to crash with a blank display, so I had to put that back into it's enabled state.
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    Laptop
    Manufacturer/Model
    Asus ZenBook Duo (UX8406MA)
    CPU
    Intel Core Ultra 9 185H
    Memory
    32 GB
    Graphics Card(s)
    Intel Arc (Meteor Lake-P)
    Hard Drives
    WD SN560 (1 TB)
    Mouse
    Asus Rog Chakram X Origin
Back
Top Bottom