I have implemented windows service:
class AppService(win32serviceutil.ServiceFramework):
and
if __name__ == '__main__':
if len(sys.argv) == 1:
servicemanager.Initialize()
servicemanager.PrepareToHostSingle(AppService)
servicemanager.StartServiceCtrlDispatcher()
else:
win32serviceutil.HandleCommandLine(AppService)
in this service I call a function to take a screenshot, if I run this function not from the service its works but from the service I get this error:
ERROR: Error taking screenshot: screen grab failed
this is the function:
def share_screen(server_api, logger):
# take screenshot and save to file
try:
logger.info("Taking screenshot")
screenshot = ImageGrab.grab()
screenshot.save(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'screenshot.png'))
logger.info("Screenshot saved")
except Exception as e:
logger.error("Error taking screenshot: %s", e)
I have understood that its could be failing because the service is not running on an interactive session, how can I make it run on interactive session or how could i resolve the problem in other way?
I have tried using the windows task scheduler but I couldnt schedule the task to run every 2 seconds from when i schedule it.
Eyal Keysar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.