首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell中的System.Printing.Addjob()错误

Powershell中的System.Printing.Addjob()错误
EN

Stack Overflow用户
提问于 2017-03-09 19:00:03
回答 1查看 126关注 0票数 1

因此,我试图创建一个脚本,它将从一个暂停的打印队列中获取一个打印作业,并将其添加到一个活动队列中。但是,我试图利用AddJob()函数,在使用或不使用参数调用它时,它返回一个异常,我不知道为什么。这是我到目前为止所拥有的

代码语言:javascript
复制
$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()中的一个错误

代码语言:javascript
复制
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

谢谢你的反馈。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-09 21:00:19

在此行中调用队列的构造函数时,将定义打印架构的版本:

代码语言:javascript
复制
$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作为值,也可以使用备用构造函数。例如:

代码语言:javascript
复制
$qPlaying = new-object System.Printing.PrintQueue -ArgumentList $server,$q.Name,$queueperms
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42703395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档