How to change screen resolution using UFT

Automation tools are equipped with so many capabilities. Though not directly, but with a workaround UFT/QTP supports changing screen resolution. This can be achieved with the help of a small dll file and DotNetFactory object of UFT.

Process to change screen resolution

before we go ahead to see how to do this, we need to understand two important things which is required by this solutions.

  1. What is DLL? DLL is a library that contains code and data that can be used by more than one program at the same time. In other words, it is the function library of windows.
  2. What is DotNetFactory? DotNetFactory is an object in UFT, which enables UFT scripts to access methods and properties of a .NET object by creating an instance of this object. This is utilised by our solution.

In order to change screen resolution, the solution is of two parts. We need to follow below steps.

  1. Write a dll file using C#. (given below)
  2. Call the above created dll file in CreateInstance function of DotNetFactory object.
Must Read:

C# code to write the DLL file

How to call the DLL in UFT script


As you can see in the program above, first we have created a dll using C# and then we have called the dll in our UFT script using DotNetFactory object. Now we can parse the arguments as int width,int height ,int frequency ,int BitsPerPel

var_CreateInstance.ChangeRes 1024,768,60,32

Parameters representing the width, height, refresh rate and, color quality

Checkout the code repo