|
|
Win10下,powershell链接其它盘的字体文件夹到系统字体文件夹下作为子文件夹,并注册其字体。
把以下内容保存为“修改字体.ps1”,然后放在你自己的字体文件夹里,以管理员权限运行它即可。
# 以管理员身份运行此脚本
# --- 配置区域 ---
# 1. 修改为你的D盘字体文件夹路径
$sourceFolder = $pwd
# 2. (可选) 修改你希望在C:\Windows\Fonts下创建的链接文件夹名称
$linkFolderName = "MyFonts"
# --- 配置结束 ---
$linkPath = "C:\Windows\Fonts\$linkFolderName"
$registryPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"
# 1. 创建符号链接
Write-Host "正在创建符号链接..."
New-Item -Path $linkPath -ItemType SymbolicLink -Target $sourceFolder -Force
# 2. 注册字体
Write-Host "正在注册字体..."
$fontFiles = Get-ChildItem -Path $linkPath -Include '*.ttf', '*.ttc', '*.otf' -Recurse
foreach ($font in $fontFiles) {
$fontName = [System.IO.Path]::GetFileNameWithoutExtension($font.Name)
if ($font.Extension -eq '.otf') {
$fontName += " (OpenType)"
} else {
$fontName += " (TrueType)"
}
$relativePath = "$linkFolderName\" + $font.Name
New-ItemProperty -Path $registryPath -Name $fontName -PropertyType String -Value $relativePath -Force
Write-Host "已注册: $($font.Name)"
}
# 3. 刷新字体缓存
Write-Host "正在刷新字体缓存..."
rundll32.exe user32.dll,UpdatePerUserSystemParameters
Write-Host "操作完成!"
|
评分
-
查看全部评分
|