vbscript 一个VBS脚本,用于监视打印队列和电子邮件,如果任何单个作业已经存在超过15分钟

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 一个VBS脚本,用于监视打印队列和电子邮件,如果任何单个作业已经存在超过15分钟相关的知识,希望对你有一定的参考价值。

'
' Save vbs file with unicode encoding, otherwise remove the table flip guy below
' Hat Tip: http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/printing/servers/
'

Const USE_LOCAL_TIME = True
Set DateTime = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
jobIsHung = false
strEmailFrom = "prntr-1@corp.com"
strEmailTo = "jpacheco@corp.com"
strSTMPServer = "smtp.corp.com"
strPrintServer = "prntr-1.corp.local"
strPrintServerFriendly = "Printer 1"

' --- END CONFIG ---

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters =  objWMIService.ExecQuery("Select * from Win32_PrintJob")
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = strPrintServerFriendly & " - Job Monitor"
objMessage.From = strEmailFrom
objMessage.To = strEmailTo
objMessage.TextBody = "Print Server: " & strPrintServer & vbCrLf & vbCrLf & _
                      "The following job(s) have been in the queue for more than 15 minutes. (╯°□°)╯︵ ┻━┻ "

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")=strSTMPServer
objMessage.TextBodyPart.Charset = "utf-8"
objMessage.Configuration.Fields.Update

For Each objPrinter in colInstalledPrinters
    DateTime.Value = objPrinter.TimeSubmitted
    dtmActualTime = DateTime.GetVarDate(USE_LOCAL_TIME)
    TimeinQueue = DateDiff("n", dtmActualTime, Now)

    If TimeinQueue > 15 Then
        jobIsHung = true
        strPrinterName = Split(objPrinter.Name,",",-1,1)
        strJob = "Printer: " & strPrinterName(0) & vbCrLf & _
                 "Print Time: " & dtmActualTime & vbCrLf & _
                 "Pages: " & objPrinter.TotalPages

        objMessage.TextBody = objMessage.TextBody & vbCrLf & vbCrLf & strJob

    End If
Next

If jobIsHung Then
    objMessage.Send
End If

以上是关于vbscript 一个VBS脚本,用于监视打印队列和电子邮件,如果任何单个作业已经存在超过15分钟的主要内容,如果未能解决你的问题,请参考以下文章

vbscript 存档文件的VBS脚本

怎么在游戏中使用vbs脚本

如何在vbs中设置可以在调用批处理脚本中读取的环境变量

vbs到底做啥用的??

VBScript基础篇

vbscript VB脚本(http://www.kanaya440.com/contents/tips/vbs/008.html)ーートカットを作成する