How can one retrieve the current screen resolution on a UiPath Studio machine through a PowerShell script, ensuring that the resolution settings for robot accounts in Orchestrator match the obtained configuration?
Introduction:
This article serves as a comprehensive guide for retrieving the current screen resolution on a UiPath Studio machine using a PowerShell script. The objective is to ensure that the resolution settings for robot accounts in Orchestrator can be configured to match the obtained screen configuration. This ensures smooth job executions, mitigating potential issues stemming from differences between the screen resolution of the Studio machine where the automation process was developed and the screen resolution of the target robot machine where the automation process is executed.
To get the screen resolution follow this procedure:
- Go to the Studio machine Start Menu, search for "PowerShell ISE" and open the app.
- PowerShell ISE (Integrated Scripting Environment) is an integrated development environment that provides a graphical interface for writing, testing, and debugging PowerShell scripts. PowerShell ISE offers several features that make it easier to develop and manage scripts in PowerShell, Microsoft's scripting and task automation language.
- Click on the "Script" down as highlighted in the below snippet.
- In the Script window of the PowerShell ISE environment (the blank side) add the following script:
-
# Add .NET class System.Windows.Forms to get screen information Add-Type -AssemblyName System.Windows.Forms
Get screen information
$screens = [System.Windows.Forms.Screen]::AllScreens
For each screen, print its information
foreach ($screen in $screens) {
Write-Host “Device Name: $($screen.DeviceName)”
Write-Host “Resolution: $($screen.Bounds.Width)x$($screen.Bounds.Height)”
Write-Host “Working Area: $($screen.WorkingArea.Width)x$($screen.WorkingArea.Height)”
Write-Host “Bits Per Pixel: $($screen.BitsPerPixel)”# To get DPI settings, we need to access registry $dpiPath = "HKCU:\Control Panel\Desktop" $logPixelsName = "LogPixels" # Try to get LogPixels value which represents DPI scale factor try { $logPixelsValue = Get-ItemPropertyValue -Path $dpiPath -Name $logPixelsName # DPI scale factor is LogPixels / 96 * 100% $dpiScale = $logPixelsValue / 96 * 100 Write-Host "Current DPI Scale: $dpiScale%" } catch { Write-Host "Failed to get DPI scale factor from registry" } Write-Host "-----------------------------"
}
- This PowerShell script collects information about the displays (monitors) available on the system and displays details such as device name, resolution, work area, number of bits per pixel, and the current DPI scale (dots per inch) for each display.
-
- To run the script and get the results from the PowerShell ISE environment (the blue side), click the "Run Script" button or press "F5" on the keyboard. As mentioned above the script collects information about the displays, including the resolution.
- Now having the resolution from the UiPath Studio machine, to replicate and update the resolution settings for the robot account follow the steps listed in the KB Article: Update Resolution Settings For Robot - Runtime Screen Resolution .
Additional Notes and Ideas:
- Resolution discrepancies between UiPath Studio and the Robot may result in issues such as errors when detecting selectors for UiElements on the screen. Consequently, critical activities like click, type into, scroll, among others, may fail, leading to the overall failure of the automated process execution.
- The same script can be used on any robot machine to confirm current screen resolution settings.
- From within the process workflow, the resolution utilized by the robot account during job execution can be logged in a Log Message activity by following the steps outlined in this KB Article: How to check resolution during robot execution.