May 6th, 2005

How Can I Make Internet Explorer Check for a New Version Each Time I Visit a Web Page?

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I make sure that Internet Explorer 6 checks for a new version on each visit to a Web page?

— MD

SpacerHey, Scripting Guy! AnswerScript Center

Hey, MD. In baseball lingo we’d call this a can of corn: a lazy fly ball we couldn’t possibly drop. This is a tricky little question but for some strange reason we just happened to know the answer. Thus a can of corn.

You know, you’re right: maybe we should do a column on baseball lingo:

Dear Baseball Lingo Guy! Are there any ways to describe how someone is pitching besides saying they’re pitching good or they’re not pitching good?

— GS

Hey, GS. You bet there is. If a pitcher is getting hit – and hit hard – it’s likely because he’s throwing meat, or maybe watermelons. If he’s pitching good he might be throwing BBs or bullets. Or maybe he’s just bringing it or throwing smoke. Or maybe …

OK, fine. But if you change your mind, send those baseball lingo questions to scripter@microsoft.com (in English, if possible).

So what about our scripting question? Well, just to make sure we’re all on the same page here, we’re talking about one of the Internet Explorer Temporary Internet Files settings. To access this through the Internet Explorer UI, click Tools, click Internet Options, and then, in the Internet Options dialog box, click Settings. You should see a dialog box that looks like this:

Internet Explorer


We’re talking about the four radio buttons at the top, the ones specifying when (or if) Internet Explorer will check for newer versions of cached Web pages.

So how can we script this? Well, it turns out that the setting for these radio buttons is stored in the registry, although in a somewhat less than intuitive location: HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\SyncMode5. If you change the value of SyncMode5, you’ll change the behavior of Internet Explorer when it comes to checking for new versions of stored pages. SyncMode5 can be set to one of four different values:

Setting

Value

Every visit to the page

3

Every time you start Internet Explorer

2

Automatically

4

Never

0

And because this is a simple DWORD registry value we can modify the setting (on remote computers as well as on the local computer) by using a WMI script just like this one:

Const HKEY_CURRENT_USER = &H80000001

strComputer = “.” Set objRegistry = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

strKeyPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings” strValueName = “SyncMode5” dwValue = 3 objRegistry.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strValueName, dwValue

The script begins by defining a constant named HKEY_CURRENT_USER and setting the value to &H80000001; we’ll use this later on to tell WMI that we want to work with the HKEY_CURRENT_USER portion of the registry. We then connect to the WMI service on the local computer; we could also connect to the WMI service on a remote machine simply by assigning the name of that computer to the variable strComputer. Note that the WMI class we need to use – StdRegProv – is found in the root\default namespace. In comparison, most WMI system administration scripts use classes found in the root\cimv2 namespace.

We then assign values to three variables:

strKeyPath, which is assigned the path to the registry key where SyncMode5 lives.

strValueName, which is assigned the name of our target registry value (SyncMode5).

dwValue, which is assigned the value 3. As we’ve already seen, if SyncMode5 is set to 3, then Internet Explorer will be configured to check for a newer version each time it visits a page.

From there we simply call the SetDWORDValue method, passing the appropriate constants and variables, and thus configuring Internet Explorer to check for a newer version each time it visits a page.

Like we also say in the baseball world, you can put this one in the book.

Author

0 comments

Discussion are closed.