我有一个安装字体的脚本,检查字体是否存在。但是,我无法验证字体的存在。脚本安装字体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