AndyS19 Posted July 7, 2015 Share Posted July 7, 2015 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 ;==>test3The Console output looks like this:Name: HP LaserJet Professional P 1102w, 2 DocName Test Page HostName: \\ANDY-LAPTOP2 Time Submitted: 20150624161307.544000-240How can I convert the "20150624161307.544000-240" value to a date and time? Link to comment Share on other sites More sharing options...
water Posted July 7, 2015 Share Posted July 7, 2015 Create an AutoIt script using Scriptomatic (can be found in the Example Scripts forum). The created script has the needed function. Example:expandcollapse popup; 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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
AndyS19 Posted July 7, 2015 Author Share Posted July 7, 2015 Excellent!! Works like a charm. Thank You Link to comment Share on other sites More sharing options...
water Posted July 7, 2015 Share Posted July 7, 2015 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now