Thursday, 30 June 2016

Working with registry key!!!

During our journey of automation, Most of the thing that we often encountered that required the update/modification of registry key.

For Example - Need to disable the auto lock functionality during execution or suppose you need to disable popup in Internet Explorer

In such scenario's working with the registry key help us to provide smooth execution-

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 Lcase(objshell.RegRead (RegLocate))=Lcase("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.


No comments:

Post a Comment