VBS Script IE "Pop-Up Blocker Allow Sites" must be run twice to work

I found a script to allow sites in the IE Pop-Up Blocker. The script works, but many times it must be run twice to actually input the sites. Any suggestions greatly appreciated.
Const HKEY_CURRENT_USER = &H80000001
 
strComputer = "."
 
Set objRegistry=GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Internet Explorer\New Windows\Allow"
strValueName = "*.ericsson.com"
strValue = Array()
objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, _
    strValueName,strValue
 
strComputer = "."
 
Set objRegistry=GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Internet Explorer\New Windows\Allow"
strValueName = "*.ericsson.net"
strValue = Array()
objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, _
    strValueName,strValue
 
strComputer = "."
 
Set objRegistry=GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Internet Explorer\New Windows\Allow"
strValueName = "*.redback.com"
strValue = Array()
objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, _
    strValueName,strValue

Open in new window

Led_ZappaAsked:
Who is Participating?
 
RobSampsonConnect With a Mentor Commented:
Oh whoops!  I just noticed that line has this:
objRegistry.CreateKey HKEY_CURRENT_USER, KeyPath

but the key path you've specified is actually in strKeyPath, so the line should be:
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath

Regards,

Rob.
Const HKEY_CURRENT_USER = &H80000001
 
strComputer = "."
 
Set objRegistry=GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Internet Explorer\New Windows\Allow"
strValue = Array()
 
On Error Resume Next
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath
Err.Clear
On Error GoTo 0
 
arrValueNames = Array("*.ericsson.com", "*.ericsson.net", "*.redback.com")
 
For Each strValueName In arrValueNames
	objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, strValueName,strValue
Next

Open in new window

0
 
Led_ZappaAuthor Commented:
FWIW: I have tried this on multiple Vista Systems with same results.

Here is where I got the instructions for the code. As a beginner, maybe I missed something.

http://www.microsoft.com/technet/scriptcenter/resources/tales/sg0605.mspx
0
 
RobSampsonCommented:
Hi, I'm not sure why you'd have to run it multiple times....but I can shorten the code for you.....

Try this out....

Regards.

Rob.
Const HKEY_CURRENT_USER = &H80000001
 
strComputer = "."
 
Set objRegistry=GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Internet Explorer\New Windows\Allow"
strValue = Array()
 
arrValueNames = Array("*.ericsson.com", "*.ericsson.net", "*.redback.com")
 
For Each strValueName In arrValueNames
	objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, strValueName,strValue
Next

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Led_ZappaAuthor Commented:
So I have noticed something that may help troubleshoot. On a new system I must run the script once and wait a couple seconds and run again. If there is an exception already there, the script works every time. If I chose "remove all" and run the script again it must be run twice. If I remove one exception and run the script the script runs fine every time.

Thanks Rob for shortening the script. I will definitely use it and compare the differences for my own education, unfortunately it did not fix my problem.
0
 
RobSampsonCommented:
Hmmm, maybe we need to make sure the "Allow" key exists before adding the exclusions....

Rob.
Const HKEY_CURRENT_USER = &H80000001
 
strComputer = "."
 
Set objRegistry=GetObject("winmgmts:\\" & _ 
    strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Microsoft\Internet Explorer\New Windows\Allow"
strValue = Array()
 
On Error Resume Next
objRegistry.CreateKey HKEY_CURRENT_USER, KeyPath
Err.Clear
On Error GoTo 0
 
arrValueNames = Array("*.ericsson.com", "*.ericsson.net", "*.redback.com")
 
For Each strValueName In arrValueNames
	objRegistry.SetBinaryValue HKEY_CURRENT_USER,strKeyPath, strValueName,strValue
Next

Open in new window

0
 
Led_ZappaAuthor Commented:
Thanks Rob,

Well this definitely deserves more points. I have discovered that the "Allow" key does not exist and is deleted when you select "Remove All" button, but the script you created still does not create the key on the first try. This is a real head scratcher.

Just another note: UAC is disabled so nothing I know of would be preventing this from happening. Especially when the code I have for adding "trusted sites" and setting IE homepage work every thime.

Thanks again for looking into this,

Shawn
0
 
RobSampsonCommented:
OK, please comment the On Error Resume Next on line 11 of my code, and see what error the CreateKey method gives you....

Regards,

Rob.
0
 
Led_ZappaAuthor Commented:
Hope I got this right:

Line: 12
Char: 1
Error: Invalid Parameter
Cose: 80041008
Source SWbemObjectEx

- Shawn
0
 
Led_ZappaAuthor Commented:
That was it!

You stayed with it and I appreciate it!

Thanks Rob!

- Shawn
0
 
RobSampsonCommented:
No problem.  Thanks for the grade.

Regards,

Rob.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.