How Can I Configure the History Setting in Internet Explorer?

ScriptingGuy1

Hey, Scripting Guy! Question

Hey, Scripting Guy! How can I configure the Days to keep pages in history setting in Internet Explorer?

— AK

SpacerHey, Scripting Guy! AnswerScript Center

Hey, AK. To tell you the truth, at first we were a little hesitant about answering this question. Why? Well, we’ve all seen enough TV to know that you aren’t supposed to mess around with history. Remember that episode of Futurama where Fry ended up becoming his own grandfather? We didn’t want that happening to any of us.

After giving it a little more thought, however, we realized that most of these TV shows dealt with regular old history; very few of them dealt specifically with Internet Explorer history settings. (Yes, it seems like a show about the history feature in Internet Explorer would be a real blockbuster, but apparently not.) And so we decided to take a chance and write the following script:

HKEY_CURRENT_USER = &H80000001

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

strKeyPath = “SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\URL History” ValueName = “DaysToKeep” dwValue = 25

objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

As you can see, this script uses WMI to directly modify the registry; that’s pretty much the only way to manage Internet Explorer settings programmatically. Some people will tell you that it can be dangerous to directly modify the registry. That’s true; it can be. However, because all we’re doing is modifying the history setting in Internet Explorer, we don’t believe any great harm can arise from running this script. Besides, we’re assuming that the danger from running the script will be counterbalanced by the danger involved in doing anything to disrupt the space-time continuum and change the course of history.

The script begins by defining a constant named HKEY_CURRENT_USER and setting the value to &H80000001; we’ll use this constant to tell the script which registry hive to work with. We then use these two lines of code to connect to the WMI service on the local computer:

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

Can you use this same approach to connect to the WMI service on a remote computer? Of course you can, and there are two ways to do that. One way is to go back in time and grab the remote computer before anyone else can get it; that way, in this era, that machine will actually be your local computer. If that sounds like more trouble than it’s worth, however, you can also simply assign the name of the remote machine to the variable strComputer. For example, this code connects you to the WMI service on the remote computer atl-ws-01:

strComputer = “atl-ws-01”
Set objReg = GetObject(“winmgmts:\\” & strComputer & “\root\default:StdRegProv”)

Next we need to assign values to three different variables:

strKeyPath. This is the path – within the HKEY_CURRENT_USER registry hive – to the registry key housing the value to be changed. In our script, that path is equal to SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\URL History.

ValueName. The name of the registry value to be changed. We want to change the Internet Explorer history setting, which happens to be stored in a value named DaysToKeep.

dwValue. The new value to be assigned to DaysToKeep. We want history information to be maintained for 25 days, so we set the variable dwValue to 25.

All we have to do now is call the SetDWORDValue method, passing as method parameters the constant HKEY_CURRENT_USER and our three variables:

objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue

The change will take effect the next time you start Internet Explorer.

Important. Like we said, the change takes effect the next time you start Internet Explorer. If the next time you start Internet Explorer you also discover that you’re your own grandfather, well, don’t say we didn’t warn you.

0 comments

Discussion is closed.

Feedback usabilla icon