Luka Posted November 30, 2007 Share Posted November 30, 2007 I want to get information for how long is some program running. (for example how long is notepad.exe running) Does somebody have some ideas how to do it? Best regards, Luka Link to comment Share on other sites More sharing options...
weaponx Posted November 30, 2007 Share Posted November 30, 2007 (edited) MsgBox(0,"","By PID (unformatted): " & ProcessStartDateTime(ProcessExists("notepad.exe")) & @CRLF & "By Name (formatted): " & ProcessStartDateTime("notepad.exe", 1)) ;PSDTid: PID or process name ;PSDTflag: 0 = Return unformatted date/time (YYYYMMDDHHMMSS.???), 1 = Return US formatted date/time (MM/DD/YYYY HH:MM:SS) Func ProcessStartDateTime($PSDTid, $PSDTflag = 0) If NOT ProcessExists($PSDTid) Then SetError(1,1,0) $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") If IsNumber($PSDTid) Then $PSDTquery = "SELECT * FROM Win32_Process WHERE ProcessId = " & $PSDTid Else $PSDTquery = "SELECT * FROM Win32_Process WHERE Name = '" & $PSDTid & "'" EndIf $colItems = $objWMIService.ExecQuery($PSDTquery, "WQL", 0x10 + 0x20) If IsObj($colItems) then For $objItem In $colItems If $PSDTflag Then Return (StringMid($objItem.CreationDate, 5, 2) & "/" & StringMid($objItem.CreationDate, 7, 2) & "/" & StringLeft($objItem.CreationDate, 4) & " " & StringMid($objItem.CreationDate, 9, 2) & ":" & StringMid($objItem.CreationDate, 11, 2) & ":" & StringMid($objItem.CreationDate,13, 2)) Else Return $objItem.CreationDate EndIf Next Else SetError(1,1,0) Endif EndFunc EDIT: Just a note, the unformatted return value is NOT compatible with TimerDiff() Edited November 30, 2007 by weaponx Link to comment Share on other sites More sharing options...
ptrex Posted November 30, 2007 Share Posted November 30, 2007 @Luka This would be an other way to monitor. ; Start Calc.exe after running this script #include <Date.au3> $strComputer = "." $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2") $objEventSource = $objWMIService.ExecNotificationQuery _ ("SELECT * FROM __InstanceOperationEvent WITHIN 5 WHERE TargetInstance ISA 'Win32_Process'") While 1 $objEventObject = $objEventSource.NextEvent() If StringRight($objEventObject.TargetInstance.Name, 4) = ".exe" Then Select Case $objEventObject.Path_.Class = "__InstanceCreationEvent" ConsoleWrite( "Calc " & $objEventObject.TargetInstance.Name & " started: " & _Now() & @LF) Case $objEventObject.Path_.Class = "__InstanceDeletionEvent" ConsoleWrite( "Calc " & $objEventObject.TargetInstance.Name & " ended: " & _Now() & @LF) EndSelect EndIf WEnd Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
weaponx Posted November 30, 2007 Share Posted November 30, 2007 ptrex, will this only monitor processes started after it is running? Link to comment Share on other sites More sharing options...
ptrex Posted November 30, 2007 Share Posted November 30, 2007 @weaponx It will start monitoring the process when it starts, and when it stops. When you substract the two. You will have the uptime of that process you want to monitor. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
weaponx Posted November 30, 2007 Share Posted November 30, 2007 (edited) @weaponxIt will start monitoring the process when it starts, and when it stops.When you substract the two. You will have the uptime of that process you want to monitor.regardsptrexNo I meant, will it show the start time for processes theat were already running before this script is executed? Edited November 30, 2007 by weaponx Link to comment Share on other sites More sharing options...
ptrex Posted December 1, 2007 Share Posted December 1, 2007 @weaponx Sorry i didn't understand your question. No it will only start monitoring as soon as the script starts. So the process time before that will not be measured. Does yours ? Regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
weaponx Posted December 1, 2007 Share Posted December 1, 2007 Yes. Since its just reading the existing process info from WMI, all that information is already stored. Yours is a good alternative for getting instant updates. Link to comment Share on other sites More sharing options...
ptrex Posted December 1, 2007 Share Posted December 1, 2007 @weaponx Yes yours is indead ready as of the startup time. Good !! I am will add some Date time conversion to it. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
ptrex Posted December 1, 2007 Share Posted December 1, 2007 @weaponx I have added some Wmi2Au3 date Calculation function expandcollapse popup#include <Date.au3> MsgBox(0,"","By PID (unformatted): " & ProcessStartDateTime(ProcessExists("notepad.exe")) & @CRLF & "By Name (formatted): " & _ ProcessStartDateTime("notepad.exe", 1) ) ;PSDTid: PID or process name ;PSDTflag: 0 = Return unformatted date/time (YYYYMMDDHHMMSS.???), 1 = Return US formatted date/time (MM/DD/YYYY HH:MM:SS) Func ProcessStartDateTime($PSDTid, $PSDTflag = 0) If NOT ProcessExists($PSDTid) Then SetError(1,1,0) $strComputer = "localhost" $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") If IsNumber($PSDTid) Then $PSDTquery = "SELECT * FROM Win32_Process WHERE ProcessId = " & $PSDTid Else $PSDTquery = "SELECT * FROM Win32_Process WHERE Name = '" & $PSDTid & "'" EndIf $colItems = $objWMIService.ExecQuery($PSDTquery, "WQL", 0x10 + 0x20) If IsObj($colItems) then For $objItem In $colItems If $PSDTflag Then ConsoleWrite("Formated : " & WMIDateStringToDate_AU3($objItem.CreationDate )& @LF) MsgBox( 4096, "", "Number of Seconds since : " & _DateDiff( 's',WMIDateStringToDate_AU3($objItem.CreationDate),_NowCalc()) ) MsgBox( 4096, "", "Number of Minutes since : " & _DateDiff( 'n',WMIDateStringToDate_AU3($objItem.CreationDate),_NowCalc()) ) MsgBox( 4096, "", "Number of Hours since : " & _DateDiff( 'h',WMIDateStringToDate_AU3($objItem.CreationDate),_NowCalc()) ) Return (StringMid($objItem.CreationDate, 5, 2) & "/" & StringMid($objItem.CreationDate, 7, 2) & "/" & _ StringLeft($objItem.CreationDate, 4) & " " & StringMid($objItem.CreationDate, 9, 2) & ":" & _ StringMid($objItem.CreationDate, 11, 2) & ":" & StringMid($objItem.CreationDate,13, 2)) Else Return $objItem.CreationDate EndIf Next Else SetError(1,1,0) Endif EndFunc Func WMIDateStringToDate_AU3($dtmDate) Return (StringLeft($dtmDate, 4) & "/" & _ StringMid($dtmDate, 5, 2) & "/" & StringMid($dtmDate, 7, 2) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc Enjoy, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
weaponx Posted April 18, 2008 Share Posted April 18, 2008 Sorry to reopen thread, just adding a cleaner version of my previous code. This returns a Date UDF compatible string. ;Return date udf compatible format $startTime = ProcessStartDateTime("notepad.exe") MsgBox(0,"",$startTime) ;PSDTid: PID or process name Func ProcessStartDateTime($PSDTid) ;Convert to process id $PSDTid = ProcessExists($PSDTid) If NOT $PSDTid Then Return SetError(1,1,0) $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") $PSDTquery = "SELECT * FROM Win32_Process WHERE ProcessId = " & $PSDTid $colItems = $objWMIService.ExecQuery($PSDTquery, "WQL", 0x10 + 0x20) If IsObj($colItems) then For $objItem In $colItems ;Return start date $tDate = $objItem.CreationDate Return StringFormat("%s/%s/%s %s:%s:%s",StringLeft($tDate, 4),StringMid($tDate, 5, 2),StringMid($tDate, 7, 2),StringMid($tDate, 9, 2), StringMid($tDate, 11, 2),StringMid($tDate,13, 2)) Next Else Return SetError(1,1,0) Endif EndFunc 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