To automate simple tasks on my laptop I use an AutoHotkey script compiled as .exe, which is started automatically when I log in and always runs in the background with administrative rights. I've been looking for a way to run programs with administrative privileges automatically in Autostart, but the integrated task scheduler of Windows 10 does not work very reliably. Many alternative solutions create the at least short appearance of a console, which is very annoying for me as a perfectionist. After some time I finally found a reliable method that works completely invisible in the background: In my App-Data Autostart folder there is a shortcut that executes the following VBScript:
Dim WShell Set WShell = CreateObject("WScript.Shell") WShell.run "cmd.exe /c C:\WINDOWS\system32\schtasks.exe /run /tn ""Test""", 0 Set WShell = Nothing
It invisibly calls the task "Test" in the Task Scheduler, which finally executes the AutoHotkey script with administration privileges.
This method works wonderfully and absolutely reliable, there is only the following problem: As soon as the energy saving mode of Windows is activated, the program running in the Taskbar Tray is immediately terminated. This is very annoying and I haven't found a way to fix the problem yet, even though I've been trying for many weeks now.
My first assumption was that when Windows is in energy saving mode, it considers the script to be unnecessary and therefore terminates it. But I can't find any way to set an exception: In normal settings, it doesn't appear as an app, so the option to exclude it from power-saving measures is missing. Running the script with a high priority does not help either, and the Task Manager's Power Throttling column under Details in the Power Throttling column for this process shows that any power-saving measure for the process is already disabled.
So I looked into the autostart process and found that the problem does not occur when I run the script directly or when I start the Task Scheduler task manually. It only occurs when I start the task using the VBScript, even though the script appears in the Task Manager with the same priority level in the end result and I can't see any other difference between the instances.
I wanted to ask here if anyone has any idea what is causing this behavior of Windows. I would be very grateful for a solution that would either allow me to define an exception for Windows' energy saving measures, modify the VBScript so that the error no longer occurs, or solve the problem in another way.
Edit: It's also interesting to note that the problem only occurs when Windows 10 automatically switches to sleep mode according to the set battery limit; if you manually activate sleep mode, it will not terminate the script.