|
| 1 | +--- |
| 2 | +title: Take Screenshot Action Fails in Unattended Mode |
| 3 | +description: Resolves an error that occurs in the Take screenshot action when you run an unattended desktop flow in Microsoft Power Automate for desktop. |
| 4 | +ms.author: iomavrid |
| 5 | +author: yiannismavridis |
| 6 | +ms.custom: sap:Desktop flows\Unattended flow runtime errors |
| 7 | +ms.date: 04/24/2025 |
| 8 | +--- |
| 9 | +# Unattended desktop flow run fails with the "Failed to take screenshot" error |
| 10 | + |
| 11 | +This article provides a resolution for an error that occurs in the [Take screenshot](/power-automate/desktop-flows/actions-reference/workstation#takescreenshotbase) action when running an unattended desktop flow in Microsoft Power Automate for desktop. |
| 12 | + |
| 13 | +## Symptoms |
| 14 | + |
| 15 | +The **Take screenshot** action fails with the following error message: |
| 16 | + |
| 17 | +```output |
| 18 | +Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.ActionException: Failed to take screenshot. ---> System.ComponentModel.Win32Exception: The handle is invalid |
| 19 | + at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) |
| 20 | + at System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize) |
| 21 | + at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.SystemActions.TakeScreenShot(Variant fileName, Variant screenToCapture, Int32 screenCaptureOption, Boolean copyToClipboard, Int32 fileFormat) |
| 22 | + --- End of inner exception stack trace --- |
| 23 | + at Microsoft.Flow.RPA.Desktop.Modules.System.Actions.TakeScreenshotBase.Execute(ActionContext context) |
| 24 | + at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments) |
| 25 | +``` |
| 26 | + |
| 27 | +## Cause |
| 28 | + |
| 29 | +The issue occurs due to a specific security policy that impacts how a User Account Control (UAC) window (for administrative privileges) is prompted. This policy prevents the flow from accessing the screen and capturing the screenshot. |
| 30 | + |
| 31 | +## Resolution 1: Locate and allow binaries except for non-Windows ones to run without elevation prompt |
| 32 | + |
| 33 | +To solve this issue: |
| 34 | + |
| 35 | +1. In Local Group Policy Editor, go to **Computer Configuration** > **Windows Settings** > **Security Settings** > **Local Policies** > **Security Options**. |
| 36 | +1. Locate the **User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode** security policy setting. |
| 37 | +1. Set the value to **Prompt for consent for non-Windows binaries**. |
| 38 | + |
| 39 | + :::image type="content" source="media/take-screenshot-action-fails-in-unattended-mode/local-security-policy.png" alt-text="Screenshot of the User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode setting in the Local Security Policy window." lightbox="media/take-screenshot-action-fails-in-unattended-mode/local-security-policy.png"::: |
| 40 | + |
| 41 | +For more information about the best practices, location, values, policy management and security considerations for the security policy setting, see [User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode](/previous-versions/windows/it-pro/windows-10/security/threat-protection/security-policy-settings/user-account-control-behavior-of-the-elevation-prompt-for-administrators-in-admin-approval-mode). |
| 42 | + |
| 43 | +## Resolution 2: Change the registry key |
| 44 | + |
| 45 | +Modify the registry key to adjust the UAC behavior: |
| 46 | + |
| 47 | +- Hive: **HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System** |
| 48 | +- Registry key name: [ConsentPromptBehaviorAdmin](/windows/security/application-security/application-control/user-account-control/settings-and-configuration?tabs=reg#user-account-control-configuration) |
| 49 | +- Type: DWORD |
| 50 | +- Value: **5** |
| 51 | + |
| 52 | +Options for the **ConsentPromptBehaviorAdmin** key: |
| 53 | + |
| 54 | +- **0** = Elevate without prompting |
| 55 | +- **1** = Prompt for credentials on the secure desktop |
| 56 | +- **2** = Prompt for consent on the secure desktop |
| 57 | +- **3** = Prompt for credentials |
| 58 | +- **4** = Prompt for consent |
| 59 | +- **5** (Default) = Prompt for consent for non-Windows binaries. Set the registry key to this value. |
| 60 | + |
| 61 | +## More information |
| 62 | + |
| 63 | +[User Account Control settings and configuration](/windows/security/application-security/application-control/user-account-control/settings-and-configuration) |
0 commit comments