[Windows] Black screen when used from Task scheduler (+fix)
See original GitHub issueGeneral information:
- OS name: Windows10
- OS architecture: 64 bits
- Resolutions: 2k monitor Blenq
- Python version: 3.7.32
- MSS version: 5.0.0.
Description of the warning/error
I’m using this Python code to generate a Windows 10 desktop screenshot every 10 seconds and save it in d:/screen/work/ folder. It works very well and extremely fast . I execute the code from Windows command prompt (cmd.exe)
python d:/screeen/screen.py
import mss
import mss.tools
import datetime
import time
count = 0
while count < 100000000:
with mss.mss() as sct:
monitor = sct.monitors[1]
timestr = time.strftime("%Y%m%d-%H%M%S")
sct.compression_level = -1
output = "d:/screen/work/" + (timestr) + ".png".format(**monitor)
sct_img = sct.grab(monitor)
mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
print(output)
time.sleep(10)
count += 1
The problem starts when I try to automatize the script. I want the script starts automatically when I turn on the computer and I loggin in and I do not want the command window appears. I followed this guide https://www.howtogeek.com/tips/how-to-run-a-scheduled-task-without-a-command-window-appearing/
When I login in computer the Pyhton script starts correctly , no command window appears, but in my d:/screen/work/ folder are saved only full black screenshots !
How to avoid this ?
Thank you
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Only black screen after login, but task manager works
For Windows 10 (Version 1709), select the Start button, select Settings > Accounts > Sign-in options, then make sure Use my sign in...
Read more >8 Best Ways to Fix Black Screen Issue on Windows Computer
If you see a cursor on the black screen, it means you need to restart Windows Explorer. Press Ctrl + Alt + Delete...
Read more >Windows Display showing black screen after killing a process ...
Then in the Task Manager, click File, New Task (Run…). Then type: explorer.exe. Then click “OK“. The above step will definitely solve the...
Read more >How to fix black screen problems on Windows 10
If you see a black screen on Windows 10, you can check the video ... Use the "Ctrl + Shift + Esc" keyboard...
Read more >4 Ways to Fix the Windows 10 Task Scheduler When It ...
1. Fix the Task Scheduler Using the Registry Editor · To get started, press the Windows Key + R, type regedit, and press...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, great news, thanks for the fix 😃
And if I may, you could rewrite your code to something like that (using MSS.shot()):
I have the same problem.
pythonw.exe
didn’t solve it.My code is very simple:
I’m using the “Start a program action” in the task scheduler, with the following parameters:
E:\Users\user\miniconda3\envs\myenv\pythonw.exe
E:\Users\user\Documents\Code\myscript\myscript.py
E:\Users\user\Desktop
It doesn’t work even when I’m logged on or if I trigger the task manually.
Interestingly, I can open a PowerShell from the desktop, run the exact command in the task (
E:\Users\user\miniconda3\envs\myenv\pythonw.exe E:\Users\user\Documents\Code\myscript\myscript.py
) and it works like a charm, so I’m guessing it’s something specific to the scheduler.@BoboTiG please let me know if you rather have a new issue for this.