{"id":68333,"date":"2005-12-14T14:08:00","date_gmt":"2005-12-14T14:08:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/12\/14\/how-can-i-configure-the-history-setting-in-internet-explorer\/"},"modified":"2005-12-14T14:08:00","modified_gmt":"2005-12-14T14:08:00","slug":"how-can-i-configure-the-history-setting-in-internet-explorer","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-configure-the-history-setting-in-internet-explorer\/","title":{"rendered":"How Can I Configure the History Setting in Internet Explorer?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" height=\"34\" alt=\"Hey, Scripting Guy! Question\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"> \n<P>Hey, Scripting Guy! How can I configure the <B>Days to keep pages in history<\/B> setting in Internet Explorer?<BR><BR>&#8212; AK<\/P><IMG height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" height=\"34\" alt=\"Hey, Scripting Guy! Answer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" align=\"left\" border=\"0\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" height=\"288\" alt=\"Script Center\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" align=\"right\" border=\"0\"><\/A> \n<P>Hey, AK. To tell you the truth, at first we were a little hesitant about answering this question. Why? Well, we\u2019ve all seen enough TV to know that you aren\u2019t supposed to mess around with history. Remember that episode of <I>Futurama<\/I> where Fry ended up becoming his own grandfather? We didn\u2019t want that happening to any of <I>us<\/I>.<\/P>\n<P>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 <I>seems<\/I> 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:<\/P><PRE class=\"codeSample\">HKEY_CURRENT_USER = &amp;H80000001<\/p>\n<p>strComputer = &#8220;.&#8221;\nSet objReg = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)<\/p>\n<p>strKeyPath = &#8220;SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\URL History&#8221;\nValueName = &#8220;DaysToKeep&#8221;\ndwValue = 25<\/p>\n<p>objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue\n<\/PRE>\n<P>As you can see, this script uses WMI to directly modify the registry; that\u2019s 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\u2019s true; it <I>can<\/I> be. However, because all we\u2019re doing is modifying the history setting in Internet Explorer, we don\u2019t believe any great harm can arise from running this script. Besides, we\u2019re 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.<\/P>\n<P>The script begins by defining a constant named HKEY_CURRENT_USER and setting the value to &amp;H80000001; we\u2019ll 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:<\/P><PRE class=\"codeSample\">strComputer = &#8220;.&#8221;\nSet objReg = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)\n<\/PRE>\n<P>Can you use this same approach to connect to the WMI service on a <I>remote<\/I> 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 <I>local<\/I> computer. If that sounds like more trouble than it\u2019s 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:<\/P><PRE class=\"codeSample\">strComputer = &#8220;atl-ws-01&#8221;\nSet objReg = GetObject(&#8220;winmgmts:\\\\&#8221; &amp; strComputer &amp; &#8220;\\root\\default:StdRegProv&#8221;)\n<\/PRE>\n<P>Next we need to assign values to three different variables:<\/P>\n<TABLE class=\"\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><B>strKeyPath<\/B>. This is the path &#8211; within the HKEY_CURRENT_USER registry hive &#8211; to the registry key housing the value to be changed. In our script, that path is equal to <B>SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\URL History<\/B>.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><B>ValueName<\/B>. 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 <B>DaysToKeep<\/B>.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><B>dwValue<\/B>. 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.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>All we have to do now is call the <B>SetDWORDValue<\/B> method, passing as method parameters the constant HKEY_CURRENT_USER and our three variables:<\/P><PRE class=\"codeSample\">objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, dwValue\n<\/PRE>\n<P>The change will take effect the next time you start Internet Explorer.<\/P>\n<TABLE class=\"dataTable\" id=\"EWE\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD class=\"\">\n<P class=\"lastInCell\"><B>Important<\/B>. 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\u2019re your own grandfather, well, don\u2019t say we didn\u2019t warn you.<\/P><\/TD><\/TR><\/TBODY><\/TABLE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I configure the Days to keep pages in history setting in Internet Explorer?&#8212; AK Hey, AK. To tell you the truth, at first we were a little hesitant about answering this question. Why? Well, we\u2019ve all seen enough TV to know that you aren\u2019t supposed to mess around with history. [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[17,26,3,167,5,6],"class_list":["post-68333","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-internet-explorer","tag-registry","tag-scripting-guy","tag-using-the-internet","tag-vbscript","tag-wmi"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I configure the Days to keep pages in history setting in Internet Explorer?&#8212; AK Hey, AK. To tell you the truth, at first we were a little hesitant about answering this question. Why? Well, we\u2019ve all seen enough TV to know that you aren\u2019t supposed to mess around with history. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68333","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=68333"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68333\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=68333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}