NMS Posted September 12, 2025 Posted September 12, 2025 What I have right now is a script that locks down the system if I'm away for certain period of time. At the moment I'm checking for mouse/keyboard input however this poses a couple of issues when I'm watching a movie for example. I thought about pixel checking however this might interfere with another function I have that changes wallpaper occasionally. Checking for window titles is not very efficient and some of them don't even provide any string that would contain any usable information. So I'm looking for ideas. Perhaps someone here has faced something similar. Maybe there's a way to check if a video is being played via GPU utilization but that's not perfect either.
rcmaehl Posted September 12, 2025 Posted September 12, 2025 (edited) Check powercfg /requests. Things that don't require user input, but prevent the computer from sleeping are listed there. Edited September 12, 2025 by rcmaehl ioa747 1 My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated. My Projects WhyNotWin11, MSEdgeRedirect Cisco Finesse, Github, IRC UDF, WindowEx UDF
argumentum Posted September 12, 2025 Posted September 12, 2025 Detect if there is sound playing. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
NMS Posted September 12, 2025 Author Posted September 12, 2025 1 hour ago, argumentum said: Detect if there is sound playing. That wouldn't work as I often put music on. 1 hour ago, rcmaehl said: Check powercfg /requests. Things that don't require user input, but prevent the computer from sleeping are listed there. That is not something I have considered at all before. I'll look into it once home and see how that goes!
NMS Posted September 12, 2025 Author Posted September 12, 2025 I've tested powercfg /requests command. Supposedly that would've worked if it was perfect. However, for example I get the exact same result (see below) while being idle (sometimes only) or when listening to music. I don't know if win11 itself is doing something in the background here and why it happens on occasion only. [PROCESS] \Device\HarddiskVolume8\Program Files\Windows Media Player\wmpnetwk.exe Media Sharing has been enabled through Windows Media Player. The program I use for music playback doesn't specify it's using it unfortunately under the [PROCESS]. VLC for example does specify but then it all comes down to constantly updating code and checking for specific programs if they are shown in the output. Only Firefox behaves nicely and gives me this [PROCESS] \Device\HarddiskVolume8\Program Files\Mozilla Firefox\firefox.exe non-display request So I'm looking for any other ideas if someone has them.
rcmaehl Posted September 12, 2025 Posted September 12, 2025 (edited) 26 minutes ago, NMS said: [PROCESS] \Device\HarddiskVolume8\Program Files\Windows Media Player\wmpnetwk.exe Media Sharing has been enabled through Windows Media Player. You should be able to disable that specific one by going to Windows Settings> System> Projecting to this PC> Always off Or Opening Services.msc, finding Windows Media Player Network Sharing Service, Clicking Stop, then changing Startup Type to Manual or Disabled Edited September 12, 2025 by rcmaehl My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated. My Projects WhyNotWin11, MSEdgeRedirect Cisco Finesse, Github, IRC UDF, WindowEx UDF
NMS Posted September 12, 2025 Author Posted September 12, 2025 47 minutes ago, rcmaehl said: You should be able to disable that specific one by going to Windows Settings> System> Projecting to this PC> Always off Or Opening Services.msc, finding Windows Media Player Network Sharing Service, Clicking Stop, then changing Startup Type to Manual or Disabled Noted. Setting was disabled by default as I don't have any projecting to begin with. But the service was running so that I did set to manual. Cheers.
ioa747 Posted September 12, 2025 Posted September 12, 2025 @rcmaehl 🏆 I found the suggestion very good, I tried it and it works perfectly. I made the function so that it also accepts specific programs e.g. _IsPowerRequestActive("Microsoft.Media.Player.exe;mpc-hc64.exe") expandcollapse popup#RequireAdmin #AutoIt3Wrapper_UseX64=y #include <AutoItConstants.au3> Global Const $iActivityTimeout = 1 ; Timeout in Minute before locking the system Local $hTimer = TimerInit() While 1 If (_IsPowerRequestActive()) Then ; Power request detected, so the user is not idle ConsoleWrite("- Power request active. Resetting idle timer:" & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF) $hTimer = TimerInit() EndIf ; Check if the idle timeout has been reached If (TimerDiff($hTimer) > ($iActivityTimeout * 60000)) Then ConsoleWrite("! Idle detected: " & Round(TimerDiff($hTimer) / 1000, 3) & " seconds. Locking system..." & @LF) ; Add your system lock function here $hTimer = TimerInit() EndIf Sleep(15000) WEnd Func _IsPowerRequestActive($sCheckString = "[PROCESS];[DRIVER]") ; needed #RequireAdmin, #AutoIt3Wrapper_UseX64=y Local $iPID = Run(@ComSpec & " /c powercfg /requests", "", @SW_HIDE, $STDOUT_CHILD) Local $sOutput = "" If Not $iPID Then Return SetError(1, 0, False) ProcessWaitClose($iPID) $sOutput = StdoutRead($iPID) ;ConsoleWrite("$sOutput=" & $sOutput & @CRLF) Local $aCheck = StringSplit($sCheckString, ";") If @error Or Not IsArray($aCheck) Then Return SetError(2, 0, False) For $i = 1 To $aCheck[0] If StringInStr($sOutput, $aCheck[$i]) > 0 Then ConsoleWrite("Power request found for '" & $aCheck[$i] & "'." & @CRLF) Return True EndIf Next Return False EndFunc I know that I know nothing
NMS Posted September 13, 2025 Author Posted September 13, 2025 (edited) The example above was working only if whatever the program is sending the request to powercfg was made to do so by the developer. Which would've been perfect if everyone did that. Out of half of the programs that I tested which display a video or run in foreground while having constant GUI updates sent those requests. Which is very specific but it still applies to what I need. So I've currently settled for pixel checking in a different way than I first thought. Basically checking for multiple pixels on foreground window that is NOT desktop, taskbar or any other title-less window. Feedback is appreciated if I overlooked something. ;Pixel checking on active window Local Static $TempPixelLast[2] = [0, 0] Local $TempPixelCurrent[2] = [0, 0] Local $TempWindow = _WinAPI_GetForegroundWindow() Local $TempTitle = WinGetTitle($TempWindow) If $TempTitle And $TempTitle <> 'Program Manager' Then Local $TempPos = WinGetPos($TempWindow) $TempPixelCurrent[0] = PixelGetColor($TempPos[0] + ($TempPos[2] * 50 / 100), $TempPos[1] + ($TempPos[3] * 50 / 100)) $TempPixelCurrent[1] = PixelGetColor($TempPos[0] + ($TempPos[2] * 70 / 100), $TempPos[1] + ($TempPos[3] * 70 / 100)) EndIf ;Whatever code goes here along with the system lock-up ;Save current pixels if new for next check If $TempPixelLast[0] <> $TempPixelCurrent[0] Then $TempPixelLast[0] = $TempPixelCurrent[0] If $TempPixelLast[1] <> $TempPixelCurrent[1] Then $TempPixelLast[1] = $TempPixelCurrent[1] Edit: after further consideration I believe it's best to record the pixel data into a 2D array and then checking if all columns are equal between themselves to avoid any false-positives such as video going black on that specific function run twice in a row. There is a chance of that happening after all. The array would be updated with each new run and oldest data being removed. Edited September 13, 2025 by NMS
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now