How to read and modify Registry Settings from QTP?


I am back with an Exciting feature of QTP. Sometimes, there are certain settings that you wish that can be configured automatically before running a Test. It also doesn’t make sense to record “activities configuring those settings”. Moreover, if you configure those settings manually in one machine, then you have configure those settings again in other machine if you plan to run test in some other machine.

For example: You want to disable pop up blocker before executing Tests as some pop up windows are getting opened in some of those tests.

To do this automatically using QTP, there is only one requirement: we just have to find out the registry setting that affects the feature that you want to change..

We will take the example of pop up blocker in this case

So, to disable pop up blocker, we just need to change the following registry key to No

“HKCU\Software\Microsoft\Internet Explorer\New Windows\PopupMgr”

We have to create “Windows Shell” object and then access its inbuilt RegRead and RegWrite functions.

As the name suggests, RegRead method allows you to read the value of the specified Registry path and RegWrite allows you to modify the value of the specified registry.

Now, lets do some action:

Dim objShell, RegLocate
<blockquote>'create windows shell object
 Set objshell =CreateObject("WScript.Shell")

'disable pop up blocker in IE if enabled
 RegLocate ="HKCU\Software\Microsoft\Internet Explorer\New Windows\PopupMgr"
 msgbox objshell.RegRead (RegLocate)
 If (objshell.RegRead (RegLocate)="Yes" OR objshell.RegRead (RegLocate)="yes") Then
 objShell.RegWrite RegLocate,"No","REG_SZ"
 End If

Set objshell = Nothing

As you see in the above example, value of the specified registry is displayed using RegRead function and then if pop up blocker is enabled, then it is disabled by modifying the value of corresponding registry key.
Similarly, to configure any other setting (before running test) in any browser, MS office or any other any software, you just need to know the registry setting that affects that particular activity and you are done…