因此,我试图创建一个脚本,它将从一个暂停的打印队列中获取一个打印作业,并将其添加到一个活动队列中。但是,我试图利用AddJob()函数,在使用或不使用参数调用它时,它返回一个异常,我不知道为什么。这是我到目前为止所拥有的
$host.Runspace.ThreadOptions = "ReuseThread"
Add-Type -AssemblyName System.Printing
$permissions = [System.Printing.PrintSystemDesiredAccess]::AdministrateServer
$queueperms = [System.Printing.PrintSystemDesiredAccess]::AdministratePrinter
$server = new-object System.Printing.PrintServer -argumentList $permissions
$queues = $server.GetPrintQueues(@([System.Printing.EnumeratedPrintQueueTypes]::Shared))
foreach ($q in $queues) {
if ($q.IsPaused -eq 1)
{
$qPaused = new-object System.Printing.PrintQueue -argumentList $server,$q.Name,1,$queueperms
}
else
{
$qPlaying = new-object System.Printing.PrintQueue -ArgumentList $server,$q.Name,2,$queueperms
}
}
$byteContents = @('This is a test')
$byteContents | Out-File -FilePath "C:\testinput.txt"
[byte[]]$bytes = Get-Content -Encoding byte -Path "C:\testinput.txt"
#$printJob = $qPaused.GetJob(3).
$qPlaying.AddJob()
$jobStream = $printJob.JobStream
$jobStream | Out-GridView
#$jobStream.Write($bytes, 0, $bytes.Length)
#$jobStream.Close()这给我带来的是$qPlaying.AddJob()中的一个错误
Exception calling "AddJob" with "0" argument(s): "Specified argument was out of the range of valid values.
Parameter name: clientPrintSchemaVersion"
At line:23 char:1
+ $qPlaying.AddJob()
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentOutOfRangeException谢谢你的反馈。
发布于 2017-03-09 21:00:19
在此行中调用队列的构造函数时,将定义打印架构的版本:
$qPlaying = new-object System.Printing.PrintQueue -ArgumentList $server,$q.Name,2,$queueperms在使用PrintQueue构造器(PrintServer, String, Int32 32, PrintSystemDesiredAccess)时,Int32是打印队列架构版本。MSDN文章指出:“Windows发布的打印模式版本是”1“。当您使用2并收到超出范围的错误时,2是不可接受的值,这将是有意义的。
您可以使用1作为值,也可以使用备用构造函数。例如:
$qPlaying = new-object System.Printing.PrintQueue -ArgumentList $server,$q.Name,$queuepermshttps://stackoverflow.com/questions/42703395
复制相似问题