{"id":69183,"date":"2005-08-12T20:36:00","date_gmt":"2005-08-12T20:36:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/08\/12\/how-can-i-change-the-icon-for-an-existing-shortcut\/"},"modified":"2005-08-12T20:36:00","modified_gmt":"2005-08-12T20:36:00","slug":"how-can-i-change-the-icon-for-an-existing-shortcut","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-change-the-icon-for-an-existing-shortcut\/","title":{"rendered":"How Can I Change the Icon for an Existing Shortcut?"},"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 change the icon for an existing shortcut?<BR><BR>&#8212; DF<\/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, DF. You know, the Scripting Guys (some of them, at least) are old enough to remember a time when you would never even <I>think<\/I> about changing an icon; after all, back in those days having any icon at <I>all<\/I> was considered cool. (And if you had flying toasters on top of that, well \u2026.) But times have changed, and apparently people aren\u2019t satisfied with their icons anymore: yours is the fourth or fifth email we\u2019ve gotten in the past few weeks asking if we could demonstrate a way to change icons using a script. And you know our motto here at Scripting Guys Central: the customer is always right.<\/P>\n<P>Hey, we said that was our motto, we didn\u2019t say we actually followed it.<\/P>\n<P>Here\u2019s the script:<\/P><PRE class=\"codeSample\">Const DESKTOP = &amp;H10&amp;<\/p>\n<p>Set objShell = CreateObject(&#8220;Shell.Application&#8221;)\nSet objFolder = objShell.NameSpace(DESKTOP)<\/p>\n<p>Set objFolderItem = objFolder.ParseName(&#8220;Test Shortcut.lnk&#8221;)\nSet objShortcut = objFolderItem.GetLink<\/p>\n<p>objShortcut.SetIconLocation &#8220;C:\\Windows\\System32\\SHELL32.dll&#8221;, 13\nobjShortcut.Save\n<\/PRE>\n<P>Before getting into the details we should mention the fact that this particular script must be run locally; that\u2019s because it uses the <B>Shell<\/B> object, and the Shell object cannot be created on a remote machine. Run this on your own machine or run it as a logon script; just don\u2019t expect to run it against a remote computer. It won\u2019t work.<\/P>\n<P>As for the script itself, we begin by defining a constant named DESKTOP and setting the value to &amp;H10&amp;; this happens to be the value used by the Shell object to bind to the Desktop folder. We create an instance of the <B>Shell.Application<\/B> object, and then use the <B>NameSpace<\/B> method to bind to the user\u2019s desktop folder.<\/P>\n<TABLE id=\"EPD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. This is the <I>user\u2019s<\/I> desktop folder, and not the All Users\u2019 Desktop folder. For information on binding to All Users\u2019 Desktop or other special folders, see the <A href=\"http:\/\/null\/technet\/scriptcenter\/scripts\/desktop\/special\/default.mspx\"><B>special folder scripts<\/B><\/A> in the Script Center Script Repository.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>After binding to the folder we then call the <B>ParseName<\/B> method to bind to an individual file within that folder; as you can see here, we\u2019re binding to a file with the filename <B>Test Shortcut.lnk<\/B>:<\/P><PRE class=\"codeSample\">Set objFolderItem = objFolder.ParseName(&#8220;Test Shortcut.lnk&#8221;)\n<\/PRE>\n<P>Finally we use the <B>GetLink<\/B> property to return the ShellLinkObject object that represents the file Test Shortcut.lnk. Once we do that we\u2019re ready to change the icon, something we can do using two lines of code:<\/P><PRE class=\"codeSample\">objShortcut.SetIconLocation &#8220;C:\\Windows\\System32\\SHELL32.dll&#8221;, 13\nobjShortcut.Save\n<\/PRE>\n<P>In the first line we call the <B>SetIconLocation <\/B>method and pass it two parameters: the path to the file containing the icon (in this case, C:\\Windows\\System32\\Shell32.dll) and the index number of the icon within that file. How in the <I>world<\/I> do we know what index number to use? Here\u2019s one way to find out:<\/P>\n<TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>Find a shortcut somewhere, right-click that shortcut, and then click <B>Properties<\/B>.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>On the <B>Shortcut<\/B> tab, click <B>Change Icon<\/B>.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>In the <B>Change Icon<\/B> dialog box, click <B>Browse<\/B> and then locate the file containing your icon. If you chose C:\\Windows\\System32\\Shell32.dll then your screen should look something like this:<\/P><\/TD><\/TR><\/TBODY><\/TABLE><IMG border=\"0\" alt=\"Icons\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/icons.jpg\" width=\"296\" height=\"357\"> \n<P><BR>Icons are numbered beginning with 0 in the upper left-hand corner and continuing with all the icons in column 1. Here\u2019s a revised graphic in which we\u2019ve numbered some of the icons for you:<\/P><IMG border=\"0\" alt=\"Icons\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/iconindex.jpg\" width=\"403\" height=\"374\"> \n<P><BR>After setting the icon location and specifying the icon index, you call the <B>Save<\/B> method and &#8211; just like that &#8211; your shortcut icon will be changed. <\/P>\n<P>Now, if they had an icon of a flying toaster we could understand why you\u2019d want to use <I>that<\/I>. Otherwise\u2026.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I change the icon for an existing shortcut?&#8212; DF Hey, DF. You know, the Scripting Guys (some of them, at least) are old enough to remember a time when you would never even think about changing an icon; after all, back in those days having any icon at all was [&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,5,226],"class_list":["post-69183","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-scripting-guy","tag-vbscript","tag-windows-explorer"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I change the icon for an existing shortcut?&#8212; DF Hey, DF. You know, the Scripting Guys (some of them, at least) are old enough to remember a time when you would never even think about changing an icon; after all, back in those days having any icon at all was [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69183","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=69183"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69183\/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=69183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}