我有一個安裝字體的腳本,檢查字體是否存在。但是,我無法驗證字體的存在。腳本安裝字體powershell
$FONTS = 0x14;
$FromPath = "c:\fonts";
$ObjShell = New-Object -ComObject Shell.Application;
$ObjFolder = $ObjShell.Namespace($FONTS);
$CopyOptions = 4 + 16;
$CopyFlag = [String]::Format("{0:x}", $CopyOptions);
foreach($File in $(Get-ChildItem -Path $FromPath)){
If ((Test-Path "c:\windows\fonts\$($File.name)") -eq $False)
{ }
Else
{
$CopyFlag = [String]::Format("{0:x}", $CopyOptions);
$ObjFolder.CopyHere($File.fullname, $CopyOptions);
New-ItemProperty -Name $File.fullname -Path "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" -PropertyType string -Value $File
}
}
究竟是什麼問題? – Paul 2014-11-04 14:38:48
錯誤在(else)中,會出現一條消息,要求替換現有的字體。這不應該發生,因爲(其他)應該安裝不存在的字體! – MeuChapeu 2014-11-04 14:45:37