我怎样才能摆脱这个未经授权的访问异常?
How can I get rid of this Unauthorized Access exception?
我正在尝试创建一个脚本来自动将 pub 文件转换为 pdf:
Function Pub-PDF($f, $p)
{
$Pub = New-Object -ComObject Publisher.Application
$Doc = $Pub.Open($f)
$Doc.ExportAsFixedFormat([Microsoft.Office.Interop.Publisher.PbFixedFormatType]::pbFixedFormatTypePDF, $p)
$Doc.Close()
[gc]::Collect()
[gc]::WaitForPendingFinalizers()
$Pub.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Pub)
Remove-Variable Pub
}
Pub-PDF -f C:\Users\User\Desktop\testFolder_afr_mod1_00.pub -p C:\Users\User\Desktop\testFolder
此脚本产生以下错误:
[1]: https://i.stack.imgur.com/bsbN5.png
您传递给 -p 参数的路径需要包含文件名。试试像
Pub-PDF -f C:\Users\User\Desktop\testFolder_afr_mod1_00.pub -p C:\Users\User\Desktop\testFolder\converted.pdf
我正在尝试创建一个脚本来自动将 pub 文件转换为 pdf:
Function Pub-PDF($f, $p)
{
$Pub = New-Object -ComObject Publisher.Application
$Doc = $Pub.Open($f)
$Doc.ExportAsFixedFormat([Microsoft.Office.Interop.Publisher.PbFixedFormatType]::pbFixedFormatTypePDF, $p)
$Doc.Close()
[gc]::Collect()
[gc]::WaitForPendingFinalizers()
$Pub.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Pub)
Remove-Variable Pub
}
Pub-PDF -f C:\Users\User\Desktop\testFolder_afr_mod1_00.pub -p C:\Users\User\Desktop\testFolder
此脚本产生以下错误: [1]: https://i.stack.imgur.com/bsbN5.png
您传递给 -p 参数的路径需要包含文件名。试试像
Pub-PDF -f C:\Users\User\Desktop\testFolder_afr_mod1_00.pub -p C:\Users\User\Desktop\testFolder\converted.pdf