Windows, why can't I move font to fonts folder even though program is run as administrator?

53 Views Asked by At

I am attempted to have my code install a font file (.ttf) onto the computer so that it can be used by the program. I am attempting to do this by moving the .ttf file into the C:/Windows/Fonts folder. In order to do this, the program needs administrator permissions, and so I have used PyUAC to grant this permission. However, I still get [Errno 13] Permission denied: 'C:\\Windows\\Fonts'. Is there a way to fix this, or is what I am attempting impossible?

Code:

import pyuac
if pyuac.isUserAdmin() == False:
    try:
        pyuac.runAsAdmin()
        INITIALIZEFONT()
    except: #User denied administrator permission
        pass
else: #pyuac.isUserAdmin() == True:
    INITIALIZEFONT()
from shutil import copyfile
def INITIALIZEFONT():
    try:
        fontPath = 'C:\\myPath\\Copperplate.ttf'
        copyfile(fontPath, 'C:\\Windows\\Fonts')
    except Exception as err:
        print(err)
        breakpoint()
        input()

My breakpoint confirms that the program does indeed have administrator permission.

[Errno 13] Permission denied: 'C:\\Windows\\Fonts'
> c:/MYPATHHERE.py(19)INITIALIZEFONT()
-> input()
(Pdb) pyuac.isUserAdmin()
True
(Pdb)

This question should not be considered a duplicate because the OP is asking how to move the file, not about permissions.

1

There are 1 best solutions below

0
Ian Boyd On

This is because the C:\Windows\Fonts folder isn't a real folder.

  • it's a shell namespace extension
  • that enumerates the registry, and shows you the installed fonts as a folder
  • and you can also install fonts by right-clicking them and selecting Install
  • or you can drop-drop them into the Fonts folder.

You can't, and shouldn't, try to copy font files there. You should instead use AddFontResource

Bonus Reading from Michael Kaplan (rip):

About the Fonts folder in Windows, Part 1 (aka What are we talking about?)