Jump to content
AndyS19

Convert $PrintJob.TimeSubmitted datetime value to a date and time

Recommended Posts

AndyS19

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?

Share this post


Link to post
Share on other sites
water

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:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
AndyS19

Excellent!!   Works like a charm.  Thank You

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

  • Similar Content

    • AndyS19
      By AndyS19
      I'm writing code to manage print jobs.  The on-line searches I did showed different ways of calling a print job method.
      I see these ways of calling print job methods:
      $oPrintjob.Delete_ (Method name followed by underline) $oPrintJob.Resume() (Method name followed by open/closed parens) $oPrintJob.Status (Method name followed by nothing at all) I don't understand syntax where the method name is followed by an underline.
       
      When is it correct to use the method name followed by an underline vs the open/closed parens vs nothing at all?
    • gritts
      By gritts
      I am attempting to create a script which will poll a SQL database that is part of our internal server monitoring application. The results would then be pushed to the local growl client on my desktop. I am successful at querying the SQL database using the SQL UDF and can send growl notifications fine as well...

      What I run into is "Syntax error converting datetime from character string." when I try to query the database with the value from a previous query. (My appologies for making this sound confusing)

      For example, I query the database and return the results into a 2D array. I can display the results fine with "_ArrayDisplay". I then take the results from the query and using the next to last row from the results, get the value from the datetime column.


      $tmpDate = String($aData[$iRows-1][1]) MsgBox(0,"Date",$tmpDate)

      It is when I take the value in $tmpDate and attempt to search with it that I get the syntax error above.


      $iRval = _SQL_GetTable2D(-1, "select * from dbo.AllpagesToday WHERE PageRecip = 'SERVER_OC1' OR PageRecip = 'SERVER_ONCALL' AND Date > '" & $tmpDate & "' ORDER BY Date;", $aData, $iRows, $iColumns)
      I have also attempted to convert the date format from: 20120319090303 to 2012-03-19 09:03:03.000 to no avail.

      My conversion pieced together from other posts:

      Func _convertToDateTime($dtString) Local $newdt $newdt = StringRegExpReplace($dtString, "A(d{4})(d{2})(d{2})(d{2})(d{2})(d{2})(?:.*)","$1-$2-$3 $4:$5:$6") MsgBox(0,"Convert Results",$newdt) Return($newdt) EndFunc
      When I search using the converted datetime, it is as if the query ignored the datetime value and returns all values of the 2D array.

      $iRval = _SQL_GetTable2D(-1, "select * from dbo.AllpagesToday WHERE PageRecip = 'SERVER_OC1' OR PageRecip = 'SERVER_ONCALL' AND Date > '" & _convertToDateTime($tmpDate) & "' ORDER BY Date;", $aData, $iRows, $iColumns)
      Any suggestions? If more information is needed, let me know.
×