1

I am working as an Automation engineer and am using the automation tool which only supports Head state(UI should be visible) which automatically requires Screen resolution in the perfect state. So to maintaining the screen resolution set before running the automation I am using a PowerShell script which is written in C#. My script perfectly running when a system is having its physical monitor attached with it but the problem I am facing with my script that it is not working when multiple systems connected on a single hub and having single monitor screen. For example, If I run my script on the system which is connected to hub and I switched the hub to that system so that it gets its physical monitor that script is working fine. Otherwise if the monitor is not switched to that system that my script won't work.

My PowerShell script is as follows:

 Function Set-ScreenResolution { 

      <# 
       .Synopsis 
    Sets the Screen Resolution of the primary monitor 

       .Description 
    Uses Pinvoke and ChangeDisplaySettings Win32API to make the change

       .Example 
    Set-ScreenResolution -Width 1024 -Height 768    -Freq 60   
      #> 
param ( 
[Parameter(Mandatory=$true, 
           Position = 0)] 
[int] 
$Width, 

[Parameter(Mandatory=$true, 
           Position = 1)] 
[int] 
$Height, 

[Parameter(Mandatory=$true, 
           Position = 2)] 
[int] 
$Freq
) 

$pinvokeCode = 

      
Add-Type $pinvokeCode -ErrorAction SilentlyContinue 
[Resolution.PrmaryScreenResolution]::ChangeResolution($width,$height,$freq) 
} 

Set-ScreenResolution -Width 1366 -Height 768 -Freq 60`

If anyone having solution to my problem, please help me out here.

Thanks is advance.

Described my problem, expected the solution to my problem.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.