我想获取打印机当前的打印作业信息,所以我转到文件夹C:\Windows\System32\spool\PRINTERS
并使用以下代码获取假脱机文件信息,
Public WithEvents _universalPrinterMonitor As PrinterQueueWatch.PrinterMonitorComponent
Private Sub UniversalPrinterMonitor_JobAdded(ByVal sender As Object, ByVal args As PrinterQueueWatch.PrintJobEventArgs) Handles _universalPrinterMonitor.JobAdded
Try
Dim fs As IO.FileStream
If File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL") Then
fs = New IO.FileStream(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL", _
IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\" & args.PrintJob.JobId.ToString("D5") & ".SPL")
ElseIf File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL") Then
fs = New IO.FileStream(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL", _
IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spool\PRINTERS\FP" & args.PrintJob.JobId.ToString("D5") & ".SPL")
Else
args.PrintJob.Delete()
MessageBox.Show("There was an error occured while executing your print job, please contact your system administrator for assistance.", _
"Spool File Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Throw New Exception("Spool File Not Found. System Path: " & Environment.GetFolderPath(Environment.SpecialFolder.System) & ". Spool File Id: " & _
args.PrintJob.JobId.ToString("D5") & ".SPL")
End If
Using fs
'Thread.Sleep(1000)
Dim sr As New IO.StreamReader(fs)
Dim buffer As String
Dim isEOF As Boolean = False
Dim isColor As Boolean = False
While Not isEOF
buffer = sr.ReadLine
If buffer Is Nothing Then
isEOF = True
Exit While
End If
If buffer.Contains("RENDERMODE=COLOR") Then
isColor = True
isEOF = True
Exit While
End If
End While
但是,有时我可以正确获取打印作业的颜色类型,有时因为buffer = sr.ReadLine
返回了 NULL 对象而不能正确获取,并且我假设我的程序没有完全读取假脱机文件。
此外,我已经尝试过PrintQueueWatch
args.PrintJob.Color
,但无论我将文档颜色类型更改为“B&W”还是“Color”,它总是返回“true”
在读取假脱机文件或使用 PrintQueueWatch 时我还需要注意什么?先谢谢了~!