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

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.

2 Likes