我试图让我的代码将字体文件(
.ttf
)安装到计算机上,以便程序可以使用它。我尝试通过将 .ttf
文件移动到 C:/Windows/Fonts
文件夹中来实现此目的。为了做到这一点,程序需要管理员权限,因此我使用 PyUAC 来授予此权限。不过,我还是得到了[Errno 13] Permission denied: 'C:\\Windows\\Fonts'
。有没有办法解决这个问题,或者我尝试的方法是不可能的?
代码:
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()
我的断点确认该程序确实具有管理员权限。
[Errno 13] Permission denied: 'C:\\Windows\\Fonts'
> c:/MYPATHHERE.py(19)INITIALIZEFONT()
-> input()
(Pdb) pyuac.isUserAdmin()
True
(Pdb)
这个问题不应被视为重复,因为OP询问如何移动文件,而不是关于权限。