Issue in taking screenshot

When the process runs via Orchestrator on a schedule, the original exception is not captured because the Take Screenshot activity in the Catch block fails and throws its own error, which is the only one logged in Orchestrator.

Take screenshot: System.ComponentModel.Win32Exception (6): The handle is invalid. at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at System.Drawing.Graphics.CopyFromScreen(Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation) at UiPath.Vision.UiImage.FromScreenRegion(Rectangle region) at UiPath.Vision.UiImage..ctor(Rectangle region, Int32 rotationDegree) at UiPath.Core.Image..ctor(Region screenRegion)

How to fix this. This was working fine from last two months.

This issue occurs if there is an active or improperly closed VM session. When we manually log in to the VM and simply close the window instead of logging out, the error may occur.

→ Properly log out of the server by selecting Log out instead of just closing the VM session.

1 Like

Hi @ba12235590747

Scheduled Orchestrator jobs often run without an active desktop session. In that case, Take Screenshot cannot access the screen and throws “The handle is invalid”, which hides the original exception.

Log the original exception first, then wrap Take Screenshot in a separate Try-Catch or skip it for scheduled/unattended runs. Ensure the robot runs in an active interactive session if screenshots are required.

Hi @ba12235590747

Might be error occurs because the unattended robot has no active desktop session during the crash, so the Take Screenshot activity cannot access the screen,
fix it by ensuring the Unattended Robot logs in with a full resolution in Machine settings, avoid locking or disconnecting the VM,
and move the screenshot step into a separate Try/Catch or disable screenshot capture in unattended mode.

Happy Automation

@ba12235590747

if someone logs into machines and does not signout this error might occur as the session could not be grabbed

logon to VM and then signout and then rerun the process

cheers

login to the sever and take a screenshot manually and save it.
open the saved image properties and see the dimensions.
this should be the resolution with which your unattended session will be created during the run time. if its not the same then the screenshot action will not work as the resolution is different.

also ensure, the login happens with default settings, not defined.
regards
SG.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.