Learn about Windows PowerShell
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
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?
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 firstname.lastname@example.org (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:
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:
Every visit to the page
Every time you start Internet Explorer
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.
To change the key from the command line use:
For value 3 = Every visit to the page. In the command line, type
reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v SyncMode5 /t REG_DWORD /d 3 /f
4 = Automatically
reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v SyncMode5 /t REG_DWORD /d 4 /f
2 = Every time you start internet explorer
reg add “HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings” /v SyncMode5 /t REG_DWORD /d 2 /f