Common Issues

How to prevent “Restore your Session” dialog box after being restarted on crashing?

We, as an Automation Testers, while automating Web Application must have faced browser crash due to which, after restarting Internet Explorer comes an dialog box which asks to:

  • Either Restore Last Session
  • or Go to Home Page (screenshot below)

Image

Now, this pop up can be prevented by going to Tools > Internet Options > Advanced tab and uncheck Enable Automatic Crash Recovery option under Browsing section. This, inturn can be achieved either Manually or Automatically. However, doing it Manually is a tedious task as before running script on any machine, you need to do the above mentioned setting to prevent this dialog.

We can achieve this Automatically (doing this automatically keeps you headache free to do setting on every machine) by doing some Registry Tweaking as explained in one of my previous article.

Registry Key correspoding to above setting is: HKEY_CURRENT_USER\Software\Policies\Microsoft\Internet Explorer\Recovery\AutoRecover

Setting the Registry Value to:

  • 0 displays the notification to either restore previous session or go to homepage
  • 1 always Restore Previous Session
  • 2 always Go to Home Page

Note: Here, we are setting the Registry Value to 2 (always go to home page)


Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005

strComputer = "."

Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Policies\Microsoft\Internet Explorer\Recovery"
strValueName = "AutoRecover"

'storing the value of strValueName from strKeyPath in dwValue
objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'checking if Registry Key Exists
If cstr(IsNull(dwValue))="True" or cstr(objRegistry.EnumKey(HKEY_CURRENT_USER,strKeyPath,arrSubKeys)) <> "0" Then

msgbox "The registry key does not exist."

'setting 1 for strValueName in strKeyPath
objRegistry.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,2

objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

'checking if Registry Key still exists
If cstr(IsNull(dwValue))="True" Then

'If Registry Key still doesn't exists, then it means strKeyPath does not exist, need to create key first
objRegistry.CreateKey HKEY_CURRENT_USER,strKeyPath
objRegistry.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,2
objRegistry.GetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
msgbox dwValue
Else
msgbox "The registry key exists."
End If
Else
msgbox "The registry key exists."
End If

Advertisements

1 reply »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s