Why Does The "Take Screenshot" Activity Work Flawlessly In The Attended Mode But Fails When Run Unattended?

Getting the following error when using a "Take Screenshot activity" on an Unattended job Take Screenshot 'uipath.studio.exe PDFiu...': System.ComponentModel.Win32Exception (0x80004005): 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.Core.Image..ctor(Region screenRegion) level: Error

Issue description

Getting the following error when using a "Take Screenshot activity" on an Unattended job:

Take Screenshot 'uipath.studio.exe PDFiu...': System.ComponentModel.Win32Exception (0x80004005): 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.Core.Image..ctor(Region screenRegion)
level: Error


Resolution

As the issue can be caused by a number of reasons, check and validate the possible root causes below:

  1. Open RDP to the Robot machine, click on the Start menu, click on the User button, and then click on Sign Out. Refer to the screenshot below. Then, start the Unattended job. Test the behavior a couple of times.
  2. If the issue persists, set the Robot settings: Log in to console: No. Test the behavior again.
  3. One of the scenarios where this occurs is when the Server manager popup starts up each time during the log-on. Disabling it would help resolve the issue. Here are the steps required to achieve this:
    1. Launch the Server Manager
    2. Click on the “Manage” button in the upper right corner of the screen and select “Server Manager Properties”
    3. Check the option “Do not start Server Manager automatically at logon” and click on the “OK” button.

    Now, the Server Manager would not start automatically upon each log-on, eventually alleviating the issue being encountered with the Unattended automation.

  1. This error can also occur when the package was published as a background process and hence the Robot was unable to do the UiAutomations as the Robot sessions were not being created. To resolve it, convert the background process to the foreground one in the project settings and republish the package from Studio.

      Set the "Starts in Background" values as "No" for UiAutomations in an Unattended mode.