0

I was able to create a python service on windows 10 using this example: Is it possible to write a windows (10) service with python (standard python.org python) without compiling

Then I created a separate python file using mss to take a single screenshot of monitor 1. Everything worked fine when I run them separately. However, when i replace the text file code in the def main(self) with the screenshot code, the resulting image file is just black.

Feel like the monitor number isn't being accessed in the service, but not sure why or even if that is the issue.

Edit: The image isn't blank it's black. Updated above from blank to black.

import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import mss

class AppServerSvc (win32serviceutil.ServiceFramework):
    _svc_name_ = "TestService"
    _svc_display_name_ = "Test Service"


    def __init__(self,args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        self.hWaitStop = win32event.CreateEvent(None,0,0,None)
        socket.setdefaulttimeout(60)

    def SvcStop(self):
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                          servicemanager.PYS_SERVICE_STARTED,
                          (self._svc_name_,''))
        self.main()

    def main(self):
        # Your business logic or call to any class should be here
        with mss.mss() as sct:
            filename = sct.shot(output="C:\\Output\\mon-{mon}-.png")

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(AppServerSvc)
lauriefire
  • 15
  • 4
  • You probably need to allow service to interact with desktop https://stackoverflow.com/questions/4237225/allow-windows-service-to-interact-with-desktop – mugiseyebrows Apr 11 '22 at 18:46
  • I don't think that is it. If I install the service using the `--interactive` switch and manually check and start the service, the "Allow service to interact with desktop" option is selected, but I still receive a black image. – lauriefire Apr 11 '22 at 21:11

0 Answers0