Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Windows] Black screen when used from Task scheduler (+fix)

See original GitHub issue

General 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/

import mss
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), sct_img.size, output=output)

    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

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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

BoboTiGcommented, Feb 6, 2020

Ah, great news, thanks for the fix 😃

And if I may, you could rewrite your code to something like that (using MSS.shot()):

import mss
import time

count = 0
with mss.mss() as sct:
    sct.compression_level = -1

    while "screenshotting":
        file_path = sct.shot(output="d:/screen/work/{date:%Y%m%d-%H%M%S}.png")
        count += 1

ubalklencommented, Aug 14, 2022

I have the same problem. pythonw.exe didn’t solve it.

My code is very simple:

from mss import mss
from time import localtime, strftime
from random import random

PROB = 0.99

if random() <= PROB:
    with mss() as sct:
        filename = strftime("%d%m%Y_%H%M%S", localtime()) + ".png"
        sct.shot(mon=-1, output=filename)

I’m using the “Start a program action” in the task scheduler, with the following parameters:

  • Program/script: E:\Users\user\miniconda3\envs\myenv\pythonw.exe
  • Arguments: E:\Users\user\Documents\Code\myscript\
  • Start in: 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\ 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found