Jump to content

Problem running task in Windows Scheduler


Go to solution Solved by wysocki,

Recommended Posts

While Chrome browser is maximized, I put my Win11 computer to sleep. But when I wake it up, the browser window is reduced about 3/4 in size and the size can't be changed unless I first click the window restore button (behaves as if it was already maximized). If I maximize it, then close it entirely, then open it again it's fine. Other windows also work fine. So I wrote a script to get the Chrome handle, restore size, and maximize it. The script does what it should when I run it.

However, if I schedule the task to run when waking the task does nothing, even though Task Scheduler reports that it ran successfully! I even put code in the script to write to a log file while it runs, but the log file is empty. I trigger task scheduler with System -> Power-Troubleshooter -> 1 and it does get triggered upon wakeup. Just the task does nothing.

Why can't the task write to the log file and get my Chrome browser handle to manipulate it when it's run from Task Scheduler?

window.png

Link to comment
Share on other sites

Here's what I had:

#include <Misc.au3>
#include <array.au3>
#include <MsgBoxConstants.au3>
#include <AutoItConstants.au3>
Opt("WinTitleMatchMode",2);match any substring
xConsoleWrite("-------------RUNNING--------------" & @CRLF)
$hWnd = WinGetHandle("[REGEXPTITLE:(?i)(.* - Google Chrome.*)]")
If $hWnd = 0 Then
xConsoleWrite("Window not found!" & @CRLF)
    Exit
EndIf

$arr = WinGetPos($hWnd, "")
$iX = $arr[0]
$iY = $arr[1]
$iWidth = $arr[2]
$iHeight = $arr[3]
xConsoleWrite('State ='& WinGetState($hWnd, "") & ' iX ='& $arr[0] & ' iY ='& $arr[1] & ' iW ='& $arr[2] & ' iH ='& $arr[3] & @CRLF)
WinMove($hWnd,"",0,0,1000,800)
WinSetState($hWnd, "", @SW_MAXIMIZE)
xConsoleWrite('New State ='& WinGetState($hWnd, "") & ' iX ='& $arr[0] & ' iY ='& $arr[1] & ' iW ='& $arr[2] & ' iH ='& $arr[3] & @CRLF)

Func xConsoleWrite($parm)
    $f = fileOpen("onwake.log",1)
    FileWrite($f, @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "  " & $parm)
    fileclose($f)
EndFunc

Thanks for the referral to the FAQ. Sound's interesting, but I don't do anything regarding the active state of the window (do I?). But aside from that, why doesn't the log file get created when it runs? Also, I have tried in the scheduler -> Edit Trigger -> Delay Task: 30 seconds (which is way after the window is available) and still I get no results from the script.

How can I get this script to run once the system awakes fully from a sleep?

Link to comment
Share on other sites

I know that I know nothing

Link to comment
Share on other sites

  • Solution

@ioa747 : Changing trigger to "on workstation unlock" says it ran successfully when I logged back in after sleeping, but the program didn't create the log file nor fix the size of the Chrome window. And your first link sounded promising since it described my issue exactly. However disabling Touch UI did not fix the issue. The second link didn't seem to be relevant since it involved ALL windows being resized and my issue is only with Chrome.

BUT! It did point me to a section of the registry where the monitor data is stored:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration

So I backed up then deleted that key and when I rebooted, the keys were correctly rebuilt and my Chrome sizing issue is fixed!!!

Thanks for the tip!

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...