{"id":55693,"date":"2008-04-26T01:18:00","date_gmt":"2008-04-26T01:18:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2008\/04\/26\/hey-scripting-guy-how-can-i-install-fonts-using-a-script\/"},"modified":"2008-04-26T01:18:00","modified_gmt":"2008-04-26T01:18:00","slug":"hey-scripting-guy-how-can-i-install-fonts-using-a-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-install-fonts-using-a-script\/","title":{"rendered":"Hey, Scripting Guy! How Can I Install Fonts Using a Script?"},"content":{"rendered":"<p><img decoding=\"async\" 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\" \/> <\/p>\n<p>Hey, Scripting Guy! Is there any way I can install a font using VBScript?<br \/>&#8212; RS<\/p>\n<p><img decoding=\"async\" height=\"5\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" border=\"0\" \/><img decoding=\"async\" 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 decoding=\"async\" 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> <\/p>\n<p>Hey, RS. As a general rule, the Scripting Guy who writes this column steers clear of popular culture. (Actually, it\u2019s not just a general rule; popular culture has a restraining order which requires him to stay at least 100 yards away from it at all times.) Nevertheless, every now and then he accidentally stumbles upon a bit of popular culture that absolutely fascinates him.<\/p>\n<p>For example, just this morning he read about a movement to remove the apostrophe from the English language. As near as he can tell, there are two primary concerns that people have with the apostrophe. For one, they believe the apostrophe is way too hard to use; therefore, it should be eliminated. (This, by the way, is how you can tell that Americans are behind the movement to eliminate the apostrophe: if something is hard, then don\u2019t do it. <i>That\u2019s<\/i> the American way!)<\/p>\n<p>The other argument is this: no one uses apostrophes in text message. (You say they <i>do<\/i> use apostrophes? we say they dont.) According to this theory, text messaging is becoming more and more popular; therefore, we should adopt the same grammar, syntax, and spelling used in text messaging. <\/p>\n<p>Because, as most people would agree, text messaging should be the ultimate arbiter when it comes to the English language. <\/p>\n<table class=\"dataTable\" id=\"EFD\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\"><b>Note<\/b>. Apparently text messaging is not just influencing the use of apostrophes; it\u2019s also influencing the names that <a href=\"http:\/\/www.switched.com\/2008\/03\/31\/baby-names-being-derived-from-text-messaging\/\" target=\"_blank\"><b>parents bestow on their children<\/b><\/a>. As a public service for those of you expecting a new bundle of joy, you can find a handy list of text messaging acronyms and shorthand codes <a href=\"http:\/\/blackberryforums.pinstack.com\/609-list_acronyms_text_messaging_shorthand.html\" target=\"_blank\"><b>right here<\/b><\/a>. Please give little An our best. (An, by the way, is short for Ann, apparently because a three-letter name like Ann needs to be trimmed down a bit.) <\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>Here\u2019s a true story for you. The Scripting Guy who writes this column once worked with an editor who was also opposed to the apostrophe, but for a different reason: she didn\u2019t \u2013 sorry, she <i>did not<\/i> \u2013 believe that any word containing an apostrophe was a real word. Can\u2019t? Not a real word; it should be \u201ccannot.\u201d Doesn\u2019t? Not a real word; it should be \u201cdoes not.\u201d Debra\u2019s computer? Not a real phrase; it should be \u201cthe computer belonging to Debra.\u201d Ah, good times \u2026.<\/p>\n<table class=\"dataTable\" id=\"EBE\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\"><b>Note<\/b>. What about the phrase \u201cthe hard disk belonging to the computer?\u201d Turns out that\u2019s not a real phrase, either. Why not? Because \u201ccomputers are inanimate objects and cannot possess anything.\u201d Which seems odd to us. After all, Scripting Guy Dean Tsaltas is pretty much an inanimate object, and he possesses all sorts of things.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>So how does any of that help you install a font using VBScript? Well, to be honest, we\u2019re not sure that it does. But <i>this<\/i> should help a little:<\/p>\n<pre class=\"codeSample\">Const FONTS = &amp;H14&amp;\n\nSet objShell = CreateObject(\"Shell.Application\")\nSet objFolder = objShell.Namespace(FONTS)\nobjFolder.CopyHere \"C:\\Scripts\\Myfont.ttf\"\n<\/pre>\n<p>As it turns out, there\u2019s nothing particularly difficult about installing a new font. Suppose you have a font file named C:\\Scripts\\Myfont.ttf. How can you install that font? Here\u2019s one simple way: just drag the font into your Fonts folder. As soon as the font has been added to the folder, the operating system will immediately install the font for you.<\/p>\n<p>Which, now that we think about it, <i>is<\/i> pretty cool, isn\u2019t it?<\/p>\n<p>Of course, that might also get <i>you<\/i> to thinking; in fact, you might be thinking, \u201cHey, all I have to do is copy a font into the Fonts folder and that font will automatically be installed for me.\u201d And that\u2019s true, but with one very important caveat: you must copy the file using the Shell object. Admittedly, you can use WMI or the FileSystemObject to copy a file into the Fonts folder; however, when you do so the operating system will not automatically install the font for you. As far as we know, the only programmatic way to get Windows to recognize that a new font has been added to the Fonts folder, and thus get Windows to install that font for you, is to use the Shell object.<\/p>\n<table class=\"dataTable\" id=\"E4E\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p><b>Note<\/b>. And yes, that <i>does<\/i> make it a bit of a sticky wicket to try and install fonts on a remote computer; after all, the Shell object isn\u2019t designed to work against remote computers. One possible solution? Put your font-installing code in a logon script; after all, logon scripts always run locally. A less-elegant solution would be to copy the fonts to a remote machine, then instruct the user at that remote computer to open and close their Fonts folder. Opening and closing the Fonts folder has the net effect of installing any new fonts that are in the folder but not yet installed.<\/p>\n<p>Like we said, that\u2019s not very elegant. But it\u2019ll work.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>As for the script itself, we start out by defining a constant named FONTS and setting the value to &amp;H14&amp;; we\u2019ll use this constant to tell the script which \u201cspecial folder\u201d (i.e., the Fonts folder) we want to work with. <\/p>\n<table class=\"dataTable\" id=\"ENF\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\"><b>Note<\/b>. Couldn\u2019t we just use a hardcoded path like C:\\Windows\\Fonts to represent the Fonts folder? Sure. However, keep in mind that the Fonts folder doesn\u2019t <i>have<\/i> to be C:\\Windows\\Fonts. By using the special folders constant the script will always find the Fonts folder for us, regardless of where that folder actually lives.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>After we define the constant we create an instance of the <b>Shell.Application<\/b> object, then use the following line of code to bind to the Fonts folder:<\/p>\n<pre class=\"codeSample\">Set objFolder = objShell.Namespace(FONTS)\n<\/pre>\n<p>Once we\u2019re connected to the Fonts folder all we have to do is call the <b>CopyHere<\/b> method, specifying the complete path to the font we want to install: <\/p>\n<pre class=\"codeSample\">objFolder.CopyHere \"C:\\Scripts\\Myfont.ttf\"\n<\/pre>\n<p>It\u2019s that easy. And yes, now that you mention it, this script <i>does<\/i> work on Windows Vista; just make sure you run the script as an Administrator. Otherwise you\u2019ll get a security popup asking you if you really <i>do<\/i> want to copy a file to the Fonts folder.<\/p>\n<p>But the heck with fonts; let\u2019s get back to something people <i>really<\/i> care about: apostrophes. As a Microsoft employee, the Scripting Guy who writes this column isn\u2019t supposed to take a stand on controversial issues, at least not when publishing articles on Microsoft.com. Nevertheless, he\u2019s going to go out on a limb here and state \u2013 for the record \u2013 that he believes the apostrophe should continue to be used; he\u2019d just like to see it used a bit more correctly. Being out of touch with the way things are done these days, the Scripting Guy who writes this column still hasn\u2019t come to grips with words spelled any which way the writer pleases, nor with apostrophes put in the wrong places. <\/p>\n<p>In fact, in researching this article (yes it<i> is<\/i> kind of hard to believe that a article like this is researched, isn\u2019t it) the Scripting Guy who writes this column discovered there\u2019s a technical term for the wanton use of apostrophes: <a href=\"http:\/\/www.wordspy.com\/words\/greengrocersapostrophe.asp\" target=\"_blank\"><b>greengrocer\u2019s apostrophes<\/b><\/a>, a name bestowed in honor of grocery stores that have signs like \u201cBanana\u2019s: 5 for a Dollar\u201d and \u201cHamburger and Hot Dog Bun\u2019s Half-Price.\u201d If you have the stomach for it (and an old-fashioned curmudgeon like the Scripting Guy who writes this column really doesn\u2019t) you might check out the <a href=\"http:\/\/www.apostropheabuse.com\/\" target=\"_blank\"><b>Apostrophe Abuse<\/b><\/a> Web site. Some of the examples there will curl your hair.<\/p>\n<p>And, if you\u2019re lucky, will give you a name for your new baby as well.<\/p>\n<table class=\"dataTable\" id=\"EGH\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td class=\"\">\n<p class=\"lastInCell\"><b>Historical footnote<\/b>. Former US President Andrew Jackson once stated that he had \u201clittle respect for a man who can only think of one way to spell a word.\u201d Historians are unsure of Jackson\u2019s view on apostrophes; we\u2019ll continue to research this and keep you posted.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! Is there any way I can install a font using VBScript?&#8212; RS Hey, RS. As a general rule, the Scripting Guy who writes this column steers clear of popular culture. (Actually, it\u2019s not just a general rule; popular culture has a restraining order which requires him to stay at least 100 yards [&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,47,3,5],"class_list":["post-55693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-desktop-management","tag-general-management-tasks","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! Is there any way I can install a font using VBScript?&#8212; RS Hey, RS. As a general rule, the Scripting Guy who writes this column steers clear of popular culture. (Actually, it\u2019s not just a general rule; popular culture has a restraining order which requires him to stay at least 100 yards [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55693","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=55693"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/55693\/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=55693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=55693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=55693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}