Hey, Scripting Guy! How Can I Change Browser History Settings via the Registry?

ScriptingGuy1

Bookmark and Share

 

Hey, Scripting Guy! Question

Hey, Scripting Guy! Awhile back, I visited a really cool Web site (not yours), but I did not save it as a favorite. The site does not show up in my History folder. Is there any way I can use a script to retrieve this information? By the way, I enjoy reading about you in your opening stories. If I do not hear from you, I hope you enjoy the holidays.

— JR

 

Hey, Scripting Guy! AnswerHello JR,

Microsoft Scripting Guy Ed Wilson here. I am glad you enjoy my opening stories. I am not sure what you mean when you say the really cool Web site was not mine. Does that mean that in addition to the TechNet Script Center, the site you visited was really cool or…? Anyway, I prefer the former rather than the latter. The scripting house is ready for the upcoming holidays. The script tree has been setup and decorated with lots of cool scripts, and I am working on my new version of the Get-CoolPresents.ps1 script. Holidays are my favorite days—I definitely will enjoy the holidays. The Scripting Wife and I are even planning a trip to Kentucky to visit friends (including my old high school friend who was in my music group when I was a kid) and family.

JR, as I have said before, Windows PowerShell is not magic. Although it certainly seems to be magical from time to time, it still is not magic. If Internet Explorer is not configured to save your history, your Internet history is in a word history. As far as finding your cool Web site, I would suggest you try Bing, try to remember what about the site was so cool, and maybe you will get lucky and find the site again. If you are drawing a blank, just search for “cool Web sites” and you will find all kinds of cool things.

JR, for your current problem, the best thing we can do is to configure Internet Explorer to save your history for a longer time frame to possibly avoid this problem in the future.

There is a Hey, Scripting Guy! post from 2005 called “How Can I Configure the History Setting in Internet Explorer? That post discusses editing the registry to set the DaysToKeep value. The problem is that Internet Explorer 8 includes additional values that may override the DaysToKeep value. The Browsing history setting is accessed by clicking Tools and then Internet Options in Internet Explorer. On the General tab, click Settings in the Browsing history area. The Temporary Internet Files and History Settings dialog box shown in the following image appears. Near the bottom of the dialog box, you will see the Days to keep pages in history spin box. Click the up and down arrows to set the days an item is kept in history. This dialog box is shown here:

Image of Temporary Internet Files and History Settings dialog box


The Days to keep pages in history setting can be overridden if the Delete browsing history on exit check box is selected. The Delete browsing history on exit check box is seen here:

Image of Delete browsing history on exit check box


The Days to keep pages in history setting can be overridden, but it depends on your Delete browsing history on exit setting. As seen in the following image, the Delete Browsing History dialog box allows granular control over which items are retained. If you want to keep the browsing history of Web sites you have visited, clear the History check box. The strange thing about the dialog box is that it has no Apply button. You clear the check box, and then click the Delete button. At that point, everything except for the items you have cleared will be deleted. One important note about this dialog box: If you have added a Web site to your Favorites folder, by default all cookies, preference settings, and temporary internet files will be retained on your computer. You must clear that check box if you want to delete those items.

Image of Delete Browsing History dialog box


Now that we understand the mechanics, JR, let us look at a script that will increase the Internet Explorer history settings and exempt History from the Delete Browsing History feature.

SetInternetExplorerHistory.ps1

$CleanHistoryPath = “HKCU:SoftwareMicrosoftInternet ExplorerPrivacy”
$HistorySettingPath = “HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet SettingsUrl History”
$NumberOfDays = 60
$DontClear = 0
Set-ItemProperty -Path $CleanHistoryPath -Name CleanHistory -Value $DontClear
Set-ItemProperty -path $HistorySettingPath -name DaysToKeep -Value $NumberOfDays

The SetInternetExplorerHistory.ps1 script could have been written in two lines of code. The first four lines of code assign values to variables to make the script easier to read. The $CleanHistoryPath variable holds the path to the privacy settings in the registry that are displayed in the Delete Browsing History dialog box seen in HSG-12-3-9-3. This string assignment is shown here.

$CleanHistoryPath = “HKCU:SoftwareMicrosoftInternet ExplorerPrivacy”

The $HistorySettingPath variable holds the registry path to the Days to keep pages in history setting that is seen in the first image in this post. This string assignment is shown here:

$HistorySettingPath = “HKCU:SoftwareMicrosoftWindowsCurrentVersionInternet SettingsUrl History”

The $NumberOfDays variable holds the number of days that the history will be retained. By default, this value is 20 days; by increasing it to 60 days, we will keep 60 days’ worth of history. This value assignment is shown here:

$NumberOfDays = 60

The $DontClear variable is set to 0, which will mean do not clear the history when deleting the history:

$DontClear = 0

To write a value to the registry, you use the Set-ItemProperty cmdlet. The path parameter points to the registry key, and the name parameter refers to the registry value. The value parameter contains the new value that will be written to the registry. This is shown here:

Set-ItemProperty -Path $CleanHistoryPath -Name CleanHistory -Value $DontClear

Set-ItemProperty -path $HistorySettingPath -name DaysToKeep -Value $NumberOfDays

 

JR, that is all there is to using the registry to configure Internet Explorer history settings. This also concludes Registry Week. Tomorrow, we will open our mailbag and address those questions that don’t require a long answer—it is time once again for sensation sweeping the scripting nation, Quick-Hits Friday!

If you want to know exactly what we will be looking at tomorrow, follow us on Twitter or Facebook. If you have any questions, send e-mail to us at scripter@microsoft.com or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

 

Ed Wilson and Craig Liebendorfer, Scripting Guys

 

0 comments

Discussion is closed.

Feedback usabilla icon