Question how to kill task before PC enters sleep

Ralston18

Titan
Moderator
More information needed but very likely that you can use Task Scheduler.

What you need is some triggering event that in turn will kill the target process.

Another option would be some script (Powershell perhaps) running in the background.

Something that after X minutes of inactivity then kills the process via Stop-Process.

IF trigger THEN Stop-Process xxxx

For example:

https://shellgeek.com/stop-process-in-powershell/

What process do you wish to kill?

Identifying a specific trigger may be the more difficult part....
 
thanks for reply
so that app would be ClockTuner for Ryzen, ever since switching to windows 11, ive had sleeping bugs, ie random BSODs or just black screen during wakeup...and this app is causing it, on win10 no issues

about that triggering event...windows enter sleep without any known (to me) trigger
already tryied event id 42 (system entering sleep), but this one actually gets triggered after windows wakes up
without ctr running, sleep works, event viewer shows event id42 with time before pc sleep
but when ctr is running and wakeup from sleep breaks, eventid 42 is not there even if pc entered sleep mode and mainboard debug code also confirms 0x03 (S3 sleep), coz pc rebooted before OS wakep eve id42 is missing
so this event id42 runs after pc wakes up....

CTR doesnt run any service, it has scheduled task to start app on user logon

inactivity backroung might not help, as i usualy put pc to sleep with remote IR remote, but pc sleeps when i fell asleep :D
 

Ralston18

Titan
Moderator
What that suggests to me is that ClockTuner for Ryzen (CTR) probably needs some update or fix to become functional or workable within Windows 11.

This app?

https://www.guru3d.com/articles-pages/clocktuner-2-1-for-ryzen-(ctr)-guide,1.html

Check Forums and FAQs.

I would disable CTR and then just monitor the source website (guru3d) until some fix or new version is released.

Any sort of tinkering around could cause more problems and end badly in some manner.

= = = =

However, just as an experiment:

Have CTR running.

In Powershell as Admin using the Get-Process cmdlet are you able to identify the ProcessName for CTR?

Are you, via Powershell Admin, able to stop CTR via Stop-Process?

For example, on my system I can shutdown Notepad via Powershell using the following cmdlet:

Stop-Process -ProcessName onenoteim

The above is an experiment so if you are not comfortable testing the Stop-Process cmdlet then just skip for now.
 
Last edited:
What that suggests to me is that ClockTuner for Ryzen (CTR) probably needs some update or fix to become functional or workable within Windows 11.

This app?

https://www.guru3d.com/articles-pages/clocktuner-2-1-for-ryzen-(ctr)-guide,1.html

Check Forums and FAQs.

I would disable CTR and then just monitor the source website (guru3d) until some fix or new version is released.

Any sort of tinkering around could cause more problems and end badly in some manner.
ya this app, already reported it..but dunno if/when updated

However, just as an experiment:

Have CTR running.

In Powershell as Admin using the Get-Process cmdlet you able to identify the ProcessName for CTR?

Are you, via Powershell Admin, able to stop CTR via Stop-Process?

For example, on my system I can shutdown Notepad via Powershell using the following cmdlet:

Stop-Process -ProcessName onenoteim

The above is an experiment so if you are not comfortable testing the Stop-Process cmdlet then just skip for now.
no issue with powershell here
Stop-Process -ProcessName "CTR 2.1" kills it


side note:
im currently looking at this if that would solve it, ie killing ap from within sleep api
https://github.com/Microsoft/Detours/wiki/Using-Detours
 

Ralston18

Titan
Moderator
My thought is that if you have fallen asleep then you have become an "inactive user".

Therefore:

https://ephams.com/2017/03/powershell-log-idle-users-computer/

Modify the script to monitor just yourself (one user) for inactivity and then include a IF-THEN to execute the Stop-Process maybe just one cycle/count before the forced logoff.

Two other paths:

Get-Services and Tasklist

If you can identify any consistant change that indicates the computer is inactive (maybe the screen saver kicking in) then that change can be the trigger for Stop-Process.
 
hmm im not sure about that...there are many instances where i just press sleep button manualy

anyway...this appears to be windows bug afterall
pressing sleep button puts pc within one second into sleep
i did hookup into power management to see what it does

it looks like this, pressing sleep -> nothing
and it should be:
sends WM_POWERBROADCAST message (Notifies applications that a power-management event has occurred.), and apps/drivers should get ready for it
https://docs.microsoft.com/en-us/windows/win32/power/wm-powerbroadcast

this should be followed by PBT_APMQUERYSUSPEND, in there you can either let it be or deny it (like app has to finish something first)

once all apps are done, it sends another message, in my case of sleep its PBT_APMSUSPEND (Notifies applications that the computer is about to enter a suspended state. This event is typically broadcast when all applications and installable drivers have returned TRUE to a previous PBT_APMQUERYSUSPEND event)

this whole part is doing nothing before sleep o_O

now i did put debug messages there at first, and really nothing before sleep...all messages were broadcasted after PC woke up
so i have put BROADCAST_QUERY_DENY (to deny power state change) right at start and uhh...pc went into sleep, but it couldnt wake up, thats same issue as im experiencing with CTR
 
Last edited: