Jump to content

Recommended Posts

Posted

I'm trying to display information from my printer queues and I cannot figure how to convert the 'datetime' value returned in the "time submitted" item to a date and time.

Here's my test code:

test3()


Func test3()
    Local $str, $objWMIService, $AllPrintJobs, $PrintJob
    While 1
        $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
        $AllPrintJobs = $objWMIService.ExecQuery("SELECT * FROM Win32_PrintJob")

        For $PrintJob In $AllPrintJobs
            $str = ""
            $str &= "Name: " & $PrintJob.Name & @CRLF ; Name of the printer
            $str &= "DocName " & $PrintJob.Document & @CRLF; Documentname
            $str &= "HostName: " & $PrintJob.HostPrintQueue & @CRLF ; Computer where the Printjob started from

            ; Time the printjob was submitted
            $str &= "Time Submitted: " & $PrintJob.TimeSubmitted & @CRLF
            $str &= @CRLF
            ConsoleWrite($str & @CRLF)
            Exit ;;; TESTING ;;;
        Next

        Sleep(1000) ;Log every second
    WEnd
EndFunc   ;==>test3


The Console output looks like this:

Name:           HP LaserJet Professional P 1102w, 2
DocName         Test Page
HostName:       \\ANDY-LAPTOP2
Time Submitted: 20150624161307.544000-240

How can I convert the "20150624161307.544000-240" value to a date and time?

Posted

Create an AutoIt script using Scriptomatic (can be found in the Example Scripts forum). The created script has the needed function. Example:

; Generated by AutoIt Scriptomatic

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$colItems = ""
$strComputer = "localhost"

$Output=""
$Output = $Output & "Computer: " & $strComputer  & @CRLF
$Output = $Output & "==========================================" & @CRLF
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PrintJob", "WQL", _
                                          $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
      $Output = $Output & "Caption: " & $objItem.Caption & @CRLF
      $Output = $Output & "Color: " & $objItem.Color & @CRLF
      $Output = $Output & "DataType: " & $objItem.DataType & @CRLF
      $Output = $Output & "Description: " & $objItem.Description & @CRLF
      $Output = $Output & "Document: " & $objItem.Document & @CRLF
      $Output = $Output & "DriverName: " & $objItem.DriverName & @CRLF
      $Output = $Output & "ElapsedTime: " & WMIDateStringToDate($objItem.ElapsedTime) & @CRLF
      $Output = $Output & "HostPrintQueue: " & $objItem.HostPrintQueue & @CRLF
      $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF
      $Output = $Output & "JobId: " & $objItem.JobId & @CRLF
      $Output = $Output & "JobStatus: " & $objItem.JobStatus & @CRLF
      $Output = $Output & "Name: " & $objItem.Name & @CRLF
      $Output = $Output & "Notify: " & $objItem.Notify & @CRLF
      $Output = $Output & "Owner: " & $objItem.Owner & @CRLF
      $Output = $Output & "PagesPrinted: " & $objItem.PagesPrinted & @CRLF
      $Output = $Output & "PaperLength: " & $objItem.PaperLength & @CRLF
      $Output = $Output & "PaperSize: " & $objItem.PaperSize & @CRLF
      $Output = $Output & "PaperWidth: " & $objItem.PaperWidth & @CRLF
      $Output = $Output & "Parameters: " & $objItem.Parameters & @CRLF
      $Output = $Output & "PrintProcessor: " & $objItem.PrintProcessor & @CRLF
      $Output = $Output & "Priority: " & $objItem.Priority & @CRLF
      $Output = $Output & "Size: " & $objItem.Size & @CRLF
      $Output = $Output & "SizeHigh: " & $objItem.SizeHigh & @CRLF
      $Output = $Output & "StartTime: " & WMIDateStringToDate($objItem.StartTime) & @CRLF
      $Output = $Output & "Status: " & $objItem.Status & @CRLF
      $Output = $Output & "StatusMask: " & $objItem.StatusMask & @CRLF
      $Output = $Output & "TimeSubmitted: " & WMIDateStringToDate($objItem.TimeSubmitted) & @CRLF
      $Output = $Output & "TotalPages: " & $objItem.TotalPages & @CRLF
      $Output = $Output & "UntilTime: " & WMIDateStringToDate($objItem.UntilTime) & @CRLF
      if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_PrintJob" )
Endif


Func WMIDateStringToDate($dtmDate)

    Return (StringMid($dtmDate, 5, 2) & "/" & _
    StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _
    & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2))
EndFunc

 

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

:)

My UDFs and Tutorials:

  Reveal hidden contents

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...