none
Install fonts in windows7 with powershell

    Question

  • Hi all,
    I simply cant figure out how to install fonts, to a windows7 desktop with powershell.
    Copy the files to $fonts isnt enough, as you have to register the fonts into the registry
    Does anyonw know what command can utilize this?

    Tried this as well but it doesnt work either:


    $path = "f:\fonts"
    foreach ($file in $Path) {
    & $File
    }
    doesnt work

    Thursday, December 02, 2010 10:09 AM

Answers

  • I got it to work now :)

    Needed the param $File.fullname i my foreach clause :)

    This script will:

    1. create a local folder (c:\rapsys\fonts)
    2. copy all files from a network share to this folder (f:\NewFontsForDeployment)
    3. Install fonts on the local computer
    4. Delete the local folder
    $FONTS = 0x14
    $Path="c:\rapsys\fonts"
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)
    New-Item $Path -type directory
    Copy-Item "f:\NewFontsForDeployment\*" $Path
    $Fontdir = dir $Path
    foreach($File in $Fontdir) {
      $objFolder.CopyHere($File.fullname)
    }
    remove-item $Path -recurse
    
    
    Thanks again for your help
    • Marked as answer by Thomasberg Friday, December 10, 2010 9:23 AM
    Friday, December 10, 2010 9:23 AM

All replies

  • after doing a quick search I found that you need to create an entry here
    HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts

    just use the display name as the key and the file name as the value.

    but based on what I've read you might need to restart the box.

    if you dig around in the registry you'll see that the open and print are linked to fontview.exe (on win7) and the install is linked to fonttext.dll (from what I've read xp and up) so the question is how can you use that DLL to install the font so that you don’t have to restart.

    there is one other way to do this without restarting. there is an API function that tells the system to update (off hand I forget the name) and I've looked in to do that... not easy, but can be done... so I guess the real question is, is a reboot ok?

    Thursday, December 02, 2010 1:14 PM
  • $FONTS = 0x14
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)
    $objFolder.CopyHere("C:\test\Myfont.ttf")
    

    Translated from vbs-script here: http://edwinfriesen.nl/content/?p=130

    It should work without a restart.

    Denniver

    Thursday, December 02, 2010 10:13 PM
  • Thanks for the answer,

    But I need to install all fonts from a network share 

    The code below doesnt work

    $Path = "f:\NewFontsForDeployment\"
    $FONTS = 0x14
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)

    foreach($File in $Path) {
        $objFolder.CopyHere($File)
    }

    Do you guys have any other suggestions?

    Thanks

     

    Friday, December 03, 2010 12:46 PM
  • Yeah thats right, since Vista/Win7 you cant install from a network share and this prevents this to work as well.
    A simple solution would be to copy the fonts to the local pc first (maybe to the temp-dir) and then continue with the code above.

    Denniver

    Friday, December 03, 2010 2:16 PM
  • Hi,

    As Denniver suggested, please add the following command to copy font files to local folder:

     

    Copy-Item \\server\share\fonts\* c:\fonts

    $path="c:\fonts"

     

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, December 06, 2010 3:17 AM
    Moderator
  • Hi,

    Have you tried the suggestions? Any update is welcomed. If there is any problem, please let us know the detailed error message.

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Wednesday, December 08, 2010 7:20 AM
    Moderator
  • Sorry for the late reply I had a few days off :)

    I really appriciate you guys helping me with this issue!

    I think im close to the goal now. I have tried this code:

    $FONTS = 0x14
    $Path="c:\rapsys\fonts\"
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)

    Copy-Item "f:\NewFontsForDeployment\*" $Path

    foreach($File in $Path) {
        $objFolder.CopyHere($File)
    }

    This will create a folder named Fonts in c:\windows\fonts\ so the path to the copied files will be c:\windows\fonts\fonts\<fontname>

    What am I doing wrong?

    Thanks

    Wednesday, December 08, 2010 4:53 PM
  • Hi,

    Please change your code to:

    $FONTS = 0x14
    $Path="c:\rapsys\fonts\"
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)

    Copy-Item "f:\NewFontsForDeployment\*" $Path

    $fonts=dir $path

    foreach($font in $fonts) {
        $objFolder.CopyHere($font)
    }

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Thursday, December 09, 2010 2:58 AM
    Moderator
  • Hi Mervyn,

    It still creates a folder in c:\windows\fonts

    Do you have any other suggestions?

    Thanks

    Christian

    Thursday, December 09, 2010 7:50 AM
  • Hi,

    Based on my test, it works fine. Let’s do manual test. Delete all files in c:\rapsys\fonts, and copy one font into c:\rapsys\fonts folder, please note the font file has to be TTF. Run the script below. What’s the result?

    If it installs successfully, make sure only TTF files are in f:\NewFontsForDeployment.

    $FONTS = 0x14
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)

    $ff=dir c:\rapsys\fonts
    foreach($font in $ff) {
        $objFolder.CopyHere($font)
    }

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Friday, December 10, 2010 2:10 AM
    Moderator
  • I got it to work now :)

    Needed the param $File.fullname i my foreach clause :)

    This script will:

    1. create a local folder (c:\rapsys\fonts)
    2. copy all files from a network share to this folder (f:\NewFontsForDeployment)
    3. Install fonts on the local computer
    4. Delete the local folder
    $FONTS = 0x14
    $Path="c:\rapsys\fonts"
    $objShell = New-Object -ComObject Shell.Application
    $objFolder = $objShell.Namespace($FONTS)
    New-Item $Path -type directory
    Copy-Item "f:\NewFontsForDeployment\*" $Path
    $Fontdir = dir $Path
    foreach($File in $Fontdir) {
      $objFolder.CopyHere($File.fullname)
    }
    remove-item $Path -recurse
    
    
    Thanks again for your help
    • Marked as answer by Thomasberg Friday, December 10, 2010 9:23 AM
    Friday, December 10, 2010 9:23 AM
  •  

    Glad to hear the problem was resolved and thank you for sharing the solution. If you have more questions in the future, you’re welcomed to this forum.

    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, December 13, 2010 2:09 AM
    Moderator
  • Script works great. But is there anyway to get the script to skip fonts if they already exist in the C:\Windows\Fonts directory? Instead of prompting to replace or not?

    Thanks

    Wednesday, May 02, 2012 5:02 PM
  • Script works great. But is there anyway to get the script to skip fonts if they already exist in the C:\Windows\Fonts directory? Instead of prompting to replace or not?

    Thanks

    $objFolder.CopyHere($File.fullname,0x10) or $objFolder.CopyHere($File.fullname,0x14)

    http://msdn.microsoft.com/en-us/library/windows/desktop/bb787866(v=vs.85).aspx

    Wednesday, May 02, 2012 5:11 PM
  • I had issues with CopyHere and surpressing the prompts so I redid the foreach loop to check if installed before trying to copy. If useful, this makes assumption that filename is the same as font. In my case I add the "type" of font to end which is where the " Regular" comes from.

    foreach($File in $Fontdir)
    {
        $fontName = $File.Name.Replace(".ttf", " Regular")
       
        $objFolderItem = $objFolder.ParseName($fontName);
        if (!$objFolderItem)
        {
          $objFolder.CopyHere($File.fullname,0x14)
        }
    }

    Friday, June 08, 2012 7:26 PM
  • Thank you for the great resources everyone! I took this script, added an extra IF statement (similar to Jason's suggestion). Finally, I created a scheduled task so that my staff members can "self" install fonts without being an administrator. If needed, here are the instructions:

    http://deployhappiness.com/installing-fonts-with-powershell/


    If my answer helped you, check out my blog: DeployHappiness. Subscribe by RSS or email. 

    Tuesday, May 14, 2013 12:18 PM