{"id":67173,"date":"2006-06-06T12:02:00","date_gmt":"2006-06-06T12:02:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2006\/06\/06\/how-can-i-return-the-urls-associated-with-my-internet-explorer-favorites\/"},"modified":"2006-06-06T12:02:00","modified_gmt":"2006-06-06T12:02:00","slug":"how-can-i-return-the-urls-associated-with-my-internet-explorer-favorites","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-return-the-urls-associated-with-my-internet-explorer-favorites\/","title":{"rendered":"How Can I Return the URLs Associated with My Internet Explorer Favorites?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I return the URLs associated with my Internet Explorer Favorites?<BR><BR>&#8212; DW<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, DW. It\u2019s time for annual performance reviews here at Microsoft, which means we Scripting Guys are supposed to be looking back and detailing all the many things we\u2019ve done in the past year. Unfortunately, instead of finding things we <I>did<\/I> do it\u2019s much easier for us to find things that we <I>didn\u2019t<\/I> do. Take this question, for example. You\u2019d think we would have already written a script that returns the URLs for all of your Internet Explorer Favorites, wouldn\u2019t you? And yet, for some reason, we never have. We must have been too \u2026 busy \u2026. <\/P>\n<P>Or something.<\/P>\n<P>On the bright side, if we hurry we can get this column in before this year\u2019s review deadline. That way we\u2019ll at least have <I>one<\/I> accomplishment for the year. That might not sound like much, but it\u2019s one more accomplishment than we usually have.<\/P>\n<P>With that in mind, let\u2019s take a look at a script that returns the name and the associated URL for all the links in the Internet Explorer Favorites folder:<\/P><PRE class=\"codeSample\">Const FAVORITES = &amp;H6&amp;<\/p>\n<p>Set objShell = CreateObject(&#8220;Shell.Application&#8221;)\nSet objFolder = objShell.Namespace(FAVORITES)<\/p>\n<p>For Each objItem in objFolder.Items\n    If objItem.IsLink Then\n        Set objLink = objItem.GetLink\n        Wscript.Echo objItem.Name\n        Wscript.Echo objLink.Target\n        Wscript.Echo\n    End If\nNext\n<\/PRE>\n<P>Gee; if we had known this script was going to be <I>that<\/I> easy we would have written it a long time ago. As you can see, there isn\u2019t much to the code. We start out by creating a constant named FAVORITES and setting the value to &amp;H6&amp;; we\u2019ll use this constant to tell the script which special folder (Internet Explorer Favorites) we want to connect to. Next we create an instance of the <B>Shell.Application<\/B> object, then use the <B>Namespace<\/B> method to bind to the Favorites folder. Notice that, by using this approach, we don\u2019t have to know the actual path to the Favorites folder; the Shell object will go out and find the folder for us.<\/P>\n<P>Our next step is to check all the items in the Favorites folder and then return the URL for any links found there. To accomplish that task we first set up a For Each loop to loop through all the items in the folder. (How do we get at that collection of items? They\u2019re all part of the <B>Items<\/B> property for the folder object.) That\u2019s what we do here:<\/P><PRE class=\"codeSample\">For Each objItem in objFolder.Items\n<\/PRE>\n<P>Inside the For Each loop we use the <B>IsLink<\/B> property to determine whether or not the item in question is a shortcut file. If IsLink is True we then use the <B>GetLink<\/B> method to retrieve the shortcut properties for the file. Complicated? No; that requires just two lines of code:<\/P><PRE class=\"codeSample\">If objItem.IsLink Then\n    Set objLink = objItem.GetLink\n<\/PRE>\n<P>After retrieving the shortcut properties we then echo the shortcut <B>Name<\/B> and <B>Target<\/B>, with Target representing the URL associated with the shortcut. We then loop around and return the name and URL for the next link in the Favorites folder. That\u2019s all there is to it.<\/P>\n<P>Well, that\u2019s a good point: as handy as this might be we probably still need something besides this script to put on our performance review. On top of that, the script shows only \u201ctop-level\u201d links; that is, links found within the Favorites folder itself. Suppose you have subfolders within the Favorites folder. Will this script be able to open up those subfolders and retrieve information about the links found <I>there<\/I>? Well \u2026.<\/P>\n<P>But that\u2019s OK; we can fix that. Here\u2019s a revised script that uses a recursive subroutine to retrieve information from any subfolders found in the Favorites folder. We won\u2019t discuss this script &#8211; or the idea of recursion &#8211; in any detail today; for more information on writing recursive functions or subroutines take a look at the <A href=\"http:\/\/null\/technet\/scriptcenter\/guide\/sas_vbs_kove.mspx\" target=\"_blank\"><B>Recursion<\/B><\/A> section in the <I>Microsoft Windows 2000 Scripting Guide<\/I>. For now, we\u2019ll simply point out that the script starts out exactly the way our previous script does: it binds to the Favorites folder and walks through the collection of items, checking to see if each item is a link.<\/P>\n<P>In this revised script, however, after we check to see if each item in the folder is a link we then use the <B>IsFolder<\/B> property to determine whether or not that item happens to be a folder. If the item <I>is<\/I> a folder, we call a recursive subroutine named <B>GetSubFolderLinks<\/B>, passing the folder object as the sole parameter to the subroutine. Inside the subroutine we then use the <B>GetFolder<\/B> method to bind us to that subfolder.<\/P>\n<P>Once we\u2019ve made a connection to the subfolder we can then walk through the items found in there, retrieving the name and URL for any links, and even calling the GetSubFolderLinks subroutine should our subfolder contain sub-subfolders. We realize that\u2019s a bit hard to grasp: how can we call the GetSubFolderLinks subroutine when we\u2019re already <I>in<\/I> the GetSubFolderLinks subroutine? All we can say is this: that\u2019s the whole idea behind recursive functions and subroutines. Take a look at the <A href=\"http:\/\/null\/technet\/scriptcenter\/guide\/sas_vbs_kove.mspx\" target=\"_blank\"><B>Scripting Guide<\/B><\/A> for more information.<\/P>\n<P>Or, just run the following script and don\u2019t worry too much about it:<\/P><PRE class=\"codeSample\">Const FAVORITES = &amp;H6&amp;<\/p>\n<p>Set objShell = CreateObject(&#8220;Shell.Application&#8221;)\nSet objFolder = objShell.Namespace(FAVORITES)<\/p>\n<p>For Each objItem in objFolder.Items\n    If objItem.IsLink Then\n        Set objLink = objItem.GetLink\n        Wscript.Echo objItem.Name\n        Wscript.Echo objLink.Target\n        Wscript.Echo\n    End If\n    If objItem.IsFolder Then\n        GetSubFolderLinks(objItem)\n    End If\nNext<\/p>\n<p>Sub GetSubFolderLinks(objItem)\n    Set objSubFolder = objItem.GetFolder\n    For Each objSubItem in objSubFolder.Items\n    If objSubItem.IsLink Then\n        Set objSubLink = objSubItem.GetLink\n        Wscript.Echo objSubItem.Name\n        Wscript.Echo objSubLink.Target\n        Wscript.Echo\n    End If\n    If objSubItem.IsFolder Then\n        GetSubFolderLinks(objSubItem)\n    End If\n    Next\nEnd Sub\n<\/PRE>\n<P>And hey, no need to thank us, DW: for the Scripting Guys, it\u2019s all in a year\u2019s work.<\/P>\n<P>Um, all in <I>day\u2019s<\/I> work \u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I return the URLs associated with my Internet Explorer Favorites?&#8212; DW Hey, DW. It\u2019s time for annual performance reviews here at Microsoft, which means we Scripting Guys are supposed to be looking back and detailing all the many things we\u2019ve done in the past year. Unfortunately, instead of finding things [&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":[16,3,707,94,5],"class_list":["post-67173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-scripting-guy","tag-shell-application","tag-special-folders","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I return the URLs associated with my Internet Explorer Favorites?&#8212; DW Hey, DW. It\u2019s time for annual performance reviews here at Microsoft, which means we Scripting Guys are supposed to be looking back and detailing all the many things we\u2019ve done in the past year. Unfortunately, instead of finding things [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67173","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=67173"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/67173\/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=67173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=67173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=67173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}