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.

New contributor
Tolkien1729 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • Can you check your Event Viewer for any information about the app crashing that was captured? – Antony T. Feb 12 at 21:51
  • I tried it several times, unfortunately the Windows Event Viewer does not show any error message, – Tolkien1729 Feb 13 at 7:30

The reason it closes is because Windows automatically prevents that app from running as a background process in Battery saving mode.

To prevent this follow these steps:

1) Go into Settings. Then select System. Afterwards, select Battery

2) On the top, under the battery life estimate, you will see a choice named Battery usage by app. Select this.

3) This will give you a list of apps and their impact on the battery. Check and see if Test in this list.

4) If its there, then select Test and uncheck the choice written "Let windows decide when this app can run in background" (I use a french OS, so the exact text may differ.)

5) Then underneath, select the choice written "Authorize this app to run in background."

Test should now be able to run without limitations even on battery saving mode. The message discussed above will no longer be displayed when switching to power saving mode.

*Note that this applies only from Windows 10 version 1607 and higher. I highly suggest updating windows if you have an earlier version.

  • Thanks for the idea, I had already found this method during my search and was disappointed to find out that unfortunately the script is not listed in the apps, so you can't disable power throttling there. My laptop runs Windows 10 Pro 1909. – Tolkien1729 Feb 13 at 6:10
  • Haven't tried, but can taskscheduler.exe work as a standalone? If yes, you can always try to exchange it's .exe with say: skype.exe . Then allow skype to run as a background process. For example. C:\Programs\Skype\Skype.exe (schtasks) /run /tn ""Test""", 0 – Natsu Kage Feb 13 at 11:57
  • A very interesting idea, unfortunately the Task Scheduler is a direct part of the Windows administration programs. So in "C:\WINDOWS\system32" there are "taskschd.msc", "taskschd.dll" and "taskschdPS.dll"; I don't think it would be easy or really recommended to swap this with another program to solve the problem. – Tolkien1729 Feb 13 at 14:18
  • I have now tested to exchange it with an exe of another program, but unfortunately nothing happens anymore when calling the exe, no task can be executed anymore. – Tolkien1729 Feb 13 at 14:56

Alternate Idea: By placing both a .bat and your custom autohotkeything.exe inside of system32 folder, they will always launch as administrator.

Create a batch file with the following code:


timeout 10
cd "C:\Windows\System32"
start autohotkeything.exe

Now make a shortcut to desktop of launcher.bat. Right click it and select the below options.

enter image description here

Press [win][r] to open the run command. In here type "shell:startup". cut the shortcut from your desktop to this folder.

This should now autolaunch the batch file as administrator with a 10 sec timeout. After that it should launch your custom .exe as administrator for every bootup.

  • Thanks already for all your efforts. I followed your instructions exactly, but I ran into the following problem: With or without System32, after configuring the shortcut to run the .bat with administrator privileges, I am confronted with a UAC promt when I try to run the shortcut. And when I put it in the startup folder, nothing happens at startup; unfortunately, Windows has ignored every startup shortcut that requires administrator privileges in my experiments. – Tolkien1729 Feb 13 at 14:48
  • I guess it doesn't help that I have UAC disabled on my Dev machine. I will re-enable it and poke around. What level is your UAC set to? I am pretty sure there is a way to do this. – Antony T. Feb 13 at 19:32
  • I had it at the default level, but even if I completely disable UAC, Windows won't call startup programs that require administrator privileges. To my knowledge, the Task Scheduler is the only way to start a program at startup as administrator. – Tolkien1729 Feb 14 at 7:14

Your Answer

Tolkien1729 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.