Issue Taking Screenshot in Unattended Mode – “The handle is invalid” Error

Hello UiPath Community,

I’m currently facing an issue when trying to take a screenshot in unattended mode. During execution, the process fails with the following error message:

Take Screenshot: System.ComponentModel.Win32Exception (6): The handle is invalid.
   at System.Drawing.Graphics.CopyFromScreen(...)
   at UiPath.Vision.UiImage.FromScreenRegion(Rectangle region)
   at UiPath.Core.Image..ctor(Region screenRegion)

Details:

  • Process Name: SAP B1 CV Unatt Test Process
  • Robot Type: Unattended (swa-rpa-unattended)
  • Machine Name: SWA-RPA
  • User: SAWT\RPAUser
  • UiPath Version: 1.0.3 (process version)
  • Timestamp: 2025-10-15T22:51:31.42153-05:00

Description of the issue:
When the unattended robot tries to execute a “Take Screenshot” activity, the workflow throws the above error. It appears that the screenshot cannot be taken because no active desktop session exists at that moment.

What I’ve checked so far:

  • The process works fine in attended mode.
  • The unattended robot runs as a background process (service mode).
  • The error occurs right when the screenshot activity executes.

Request for help:
Could someone please advise the best practice for taking screenshots in unattended mode?
Should I configure the robot to log in interactively (with “Login to Console = No” and screen resolution settings), or is there a recommended headless-safe alternative for capturing images in unattended executions?

Thank you for your time and assistance!

1 Like

Hi @sanjay210no

Thanks for the response

I tried your suggestion still issue persit and same state

It looks like the issue is related to the fact that the unattended robot is running in the background without an active desktop session. Since the screenshot activity relies on interacting with the screen, it fails when no active UI session exists.

To resolve this, consider using one of the following approaches:

  1. Interactive Login: Configure the robot to log in interactively with a session (using “Login to Console = No” and proper screen resolution settings). This ensures an active desktop session where screenshots can be captured.
  2. Headless Alternatives: For headless execution, use alternatives like UiPath’s OCR or Image Recognition activities that don’t require screen access but still capture visual data.
  3. Remote Desktop: If the robot runs on a virtual machine or server, ensure RDP (Remote Desktop Protocol) is configured properly, as this can simulate an active screen session.

These approaches should help resolve the “invalid handle” error.

Hi @Sushma_Ganapatisa

By any chance, are you guys disconnecting from VM instead of logging out?

If unsure, login to VM and then sign out of the VM properly. And then run process in unattended mode with having login to console set as No. it should work.

Hope this helps.

There’s your problem. Background processes have no desktop/UI.

1 Like