r/PowerShell • u/JBizz86 • Jan 28 '26
Help .ps1 works but cant schedule it.
Please delete if this is the wrong place to ask. Out of ideas.
Im looking for help i have a working script that re-enables my screensaver (games are disabling it) Automate it with Task Scheduler (no window)
- Open Task Scheduler → Create Task...
General
- Name:
Reapply Screensaver - Check "Run with highest privileges"
- Check "Run whether user is logged on or not"
- Name:
Triggers
- At log on
- On a schedule → repeat every 10 minutes or 5 minutes, duration Indefinitely
Actions
- **Program/script:**C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- Arguments:-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Scripts\ReapplyScreensaver.ps1"
- Conditions: uncheck everything
- Settings: Check "allow run on demand"
After i do all this it doesn't trigger. What am i missing? Schedule says its doing something every 5mins but its not running the powersell script...
This is the post im following https://www.reddit.com/r/Battlefield/comments/1o4fsre/bf6_is_somehow_disabling_the_screensaverlogout_on/
2
Upvotes
3
u/Academic-Detail-4348 Jan 28 '26
No need to configure the task scheduler to run unattended as your user is the actor and the target so uncheck Whether the user is logged in or not.
Games or any full screen apps so not change system settings but merely prevent the computer or screen from entering standby. Check for Gamer Mode or Focus settings.
If you want help with Powershell then drop your code here, else this is pure Windows help thread.
2
u/BlackV Jan 29 '26 edited Feb 16 '26
add entries to your script that write to a log file in the
C:\Scriptsfoldervalidate WHERE this is changing the setting (i.e. is the running as system, is this running as the user)
validate what the before and after settings are and so on
10
u/wssddc Jan 28 '26
I notice the script uses HKCU, is the scheduled task running as you?
1
u/ninhaomah Jan 28 '26
Do a print.
Then you will know if the scheduler is working.
1
u/MapAppropriate1075 Jan 28 '26
Don't hide the window look for the error, if not take a look at the PS log file
1
u/rwh4vt Jan 28 '26
Your screensaver? You need it reapplied while playing games?
1
u/firedocter Jan 29 '26
Does it have a time in the next run time column? Make sure the user account is an admin or has run as script privileges. Does task scheduler say it is running successfully in the history tab? I have best luck with telling it to run once some time in the past. Then run every x mins.
1
u/annalesinvictus Jan 29 '26
This is what I would do:
First, remove window style parameter from command then open a command prompt as admin and run:
powershell -NoProfile -ExecutionPolicy Bypass -File "C:\Scripts\ReapplyScreensaver.ps1"
Does it run successfully getting the output you expect?
If there is an execution policy error, follow the instructions it gives you on which policy you should use instead and resolve any other errors.
Once you get a successful run in a command prompt, make sure you are running the scheduled task with highest privileges and whether the user is logged on or not options selected. Enter the credentials of an admin user. If these two options are selected then task scheduler hides the window on its own.
You can also use start-transcript -path “.\script.log” -append and stop-transcript commands at the beginning and end of the script to see what’s happening when it’s running in the task scheduler. It will output a log file to the same folder as the script.
1
u/[deleted] Jan 29 '26
Add a log. Game changer if you aren't used to it.
Then forget about the hidden window as it's shit with task scheduler. Use Conhost.exe instead. Move powershell as you have it into the arguments and forget the hidden window.
1
u/purplemonkeymad Jan 29 '26
This is probably the issue.
Part of the script is signaling the current session, but this option creates a brand new session for the task. So I don't think your current session will get that info.
Note that you will get a brief window when the task starts, if it is unchecked.
1
u/Jeffinmpls Jan 29 '26
My first step in troubleshooting is to open up a cmd line (not PowerShell command line) and run the action as is listed . Make sure to run it as the user that runs the scheduled task. If it runs without issues, you know it's not permissions issues and it's issues with your task schedular settings.
I've had limited success set tasks to run at log in, instead, I set to start at midnight (or whatever time), to run every 5 minutes for 24 hours, I've never had issues with that. I've also never had to include the entire path to the PowerShell exe as it's in the environment variables unless you messed with it. You can just use
powershell or powershell.exe
-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "C:\Scripts\ReapplyScreensaver.ps1"
You can confirm this in a command line window.
-5
u/BamBam-BamBam Jan 28 '26
Task scheduler is a piece of crap. Quoting things correctly is key.