question

RiccardoChimisso-0996 avatar image
0 Votes"
RiccardoChimisso-0996 asked MotoX80 answered

Why is Task Scheduler opening Note Block instead of running my script?

I'm on Windows 10 and I want to schedule a task to change which GPU my browser should use depending whether I am on battery or ac.
I managed to create a task as follows (I changed personal info with an all uppercase string of what they represent):
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">;
<RegistrationInfo>
<Date>2022-05-28T10:52:12.1836624</Date>
<Author>AUTHOR</Author>
<URI>\Change Opera GX GPU Setting</URI>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Kernel-Power/Thermal-Operational"&gt;&lt;Select Path="Microsoft-Windows-Kernel-Power/Thermal-Operational"&gt;*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and EventID=105]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
</EventTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>USERID</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>true</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
<RestartOnFailure>
<Interval>PT1M</Interval>
<Count>3</Count>
</RestartOnFailure>
</Settings>
<Actions Context="Author">
<Exec>
<Command>powershell</Command>
<Arguments>-ExecutionPolicy Bypass -File PATHTOSCRIPT\opera-gpu-setting-update.ps1</Arguments>
</Exec>
</Actions>
</Task>
And it works fine if I manually run the task. However if I plug my laptop it just opens the script file with Windows Notepad instead of running the script. Furthermore if I unplug my laptop the task doesn't seem to run at all (no script is being executed and Notepad does not open).

Why is this happening? How do I fix this?

windows-10-generalwindows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ELBANNOUNIMOHAMMED-6711 avatar image
0 Votes"
ELBANNOUNIMOHAMMED-6711 answered

Le planificateur de tâches Microsoft Windows vous permet de lancer automatiquement un programme ou un script PowerShell à un moment précis ou lorsque certaines conditions sont satisfaites. Il permet également de programmer l’envoi d’e-mails et même l’affichage de certains messages. Dans ce billet de blog, nous allons vous montrer comment exécuter un script PowerShell à partir du planificateur de tâches. Ce script vous alertera de toute installation de logiciel sur un ordinateur local.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RiccardoChimisso-0996 avatar image
0 Votes"
RiccardoChimisso-0996 answered

In the end Notepad opening was because I had created another task by mistake.
Anyway, I fixed the real issue by changing the Subscription as follows:
<Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="System"&gt;&lt;Select Path="System"&gt;*[System[Provider[@Name='Microsoft-Windows-Kernel-Power'] and EventID=105]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MotoX80 avatar image
0 Votes"
MotoX80 answered

You will need 2 tasks, correct? One when you go from battery to AC (set gpu to full) and the other for AC to battery (set gpu to low power). Or does your script look at the event to which power mode is set?

Notepad is the default association for .ps1 files. So if you see notepad running then somewhere you are trying to run a .ps1 file without specifying the executable "powershell.exe C:\Myscript.ps1".

In your tasks verify that the program is "powershell.exe" or maybe even the full path; "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe".

In the task scheduler's action pane, enable all tasks history so that you can see when it was run.

You might also want to add a start and stop-transcript to your script to get a full log of what Powershell did.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/start-transcript?view=powershell-5.1

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.host/stop-transcript?view=powershell-5.1

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hi there,

If the task scheduler works only when you plug the Laptop try changing the Power Conditions for the task and see if that helps. To do this, refer the steps mentioned below:

-Press Windows logo key + R, to open Run dialog box.
-Type taskschd.msc and click on OK.
-Click on Task Scheduler Library.
-Double click on the task that you have created, navigate to the Conditions tab.
-Under Power, clear the checkbox for Stop if the computer switches to battery power.



--If the reply is helpful, please Upvote and Accept it as an answer--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.