Internet explorer 在Windows Server 2012上使用Powershell打开IE
我们有几个经典的ASP应用程序,它们最终需要从web服务器向打印机打印报告 我使用来自用户的输入在服务器(服务器端)上构建报告。我将其存储在服务器上的html文件中。然后将文件名和printername传递给powershell脚本。powershell脚本正在调用IE并打印文件。精彩的!别那么快 在我的电脑上,它工作得很好(我正在运行IIS,所以它应该是模仿web服务器) 但是,当我将其全部放在web服务器上时,我在日志中得到的错误是: 错误号:-2147024891 错误描述:检索CLSID为{0002DF01-0000-0000-C000-0000000000 46}的组件的COM类工厂失败,原因是以下错误:80070005访问被拒绝。(来自HRESULT的异常:0x80070005(E_ACCESSDENIED)) 错误源:Internet explorer 在Windows Server 2012上使用Powershell打开IE,internet-explorer,powershell,iis,asp-classic,Internet Explorer,Powershell,Iis,Asp Classic,我们有几个经典的ASP应用程序,它们最终需要从web服务器向打印机打印报告 我使用来自用户的输入在服务器(服务器端)上构建报告。我将其存储在服务器上的html文件中。然后将文件名和printername传递给powershell脚本。powershell脚本正在调用IE并打印文件。精彩的!别那么快 在我的电脑上,它工作得很好(我正在运行IIS,所以它应该是模仿web服务器) 但是,当我将其全部放在web服务器上时,我在日志中得到的错误是: 错误号:-2147024891 错误描述:检索CLSID
$ie=new object-comObject InternetExplorer.Application
Windows 2012 R2中是否有IIS设置或其他设置会导致此问题,并且更改它会使其正常工作
Powershell如下所示:
Function LogWrite
{
Param ([string]$logstring)
Add-content $Logfile -value $logstring
}
$newline = [Environment]::NewLine
$FileName = $args[0]
$PrinterName = $args[1]
$Logfile = $args[2]
$strReturn = "0^Successful"
"Filename: " + $FileName
"Printer: " + $PrinterName
#Send To named printer
try
{
#Change the Default Printer
(Get-WmiObject -ComputerName . -Class Win32_Printer -Filter "Name='$PrinterName'").SetDefaultPrinter()
#Print a file from Microsoft Word (which can apply formatting changes)
$ie = new-object -comObject InternetExplorer.Application
$ie.Navigate($FileName)
while ( $ie.busy ) { Start-Sleep -second 5 }
$ie.ExecWB(6,2)
}
catch
{
$strMessage = $error[0].Exception.Message
$strHResult = $error[0].Exception.HResult
$strLine = $error[0].InvocationInfo.Line
$strReturn = "1^Error attempting to print report.^" + $strHResult + "^" + $strMessage + "^Line: " + $strLine
}
finally
{
# garbage collection
[gc]::collect()
[gc]::WaitForPendingFinalizers()
#exit $strReturn
}
# write to a log file
# Log file time stamp:
$LogTime = Get-Date -Format "MM/dd/yyyy@hh:mm:ss"
$LogRecord = $LogTime + "^" + $FileName + "^" + $PrinterName + "^" + $strReturn
LogWrite $LogRecord
$strReturn
几乎可以肯定,这是一个权限问题。您可能需要: