Answered by:
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
Answers
-
I got it to work now :)
Needed the param $File.fullname i my foreach clause :)
This script will:
- create a local folder (c:\rapsys\fonts)
- copy all files from a network share to this folder (f:\NewFontsForDeployment)
- Install fonts on the local computer
- Delete the local folder
Thanks again for your help$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
- Marked as answer by Thomasberg 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\Fontsjust 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?
-
$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
- Proposed as answer by Denniver ReiningMVP Thursday, December 2, 2010 10:14 PM
- Marked as answer by Mervyn Zhang Friday, December 3, 2010 6:34 AM
- Unmarked as answer by Thomasberg Friday, December 10, 2010 9:23 AM
- Unproposed as answer by Thomasberg Friday, December 10, 2010 9:23 AM
-
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
-
-
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. -
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. -
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
-
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. -
-
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. -
I got it to work now :)
Needed the param $File.fullname i my foreach clause :)
This script will:
- create a local folder (c:\rapsys\fonts)
- copy all files from a network share to this folder (f:\NewFontsForDeployment)
- Install fonts on the local computer
- Delete the local folder
Thanks again for your help$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
- Marked as answer by Thomasberg 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. -
-
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
-
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)
}
} -
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.
-