Create a Window in Autoit That Updates as Process Continues
I was curious if it was possible to find out the time a window was created or a process was started, without monitoring for the creation by the script (i.e. if it was started before the script).
I've looked through window and process related dll call functions but haven't spotted any way.
It would be interesting to know when the process was created in order to switch to the most recently created windows, which may not necessarily be the same as in the order of the window list (alt-tab list) if some time has passed since they were created and the user has changed to a different window in between.
#1 - Posted 04 January 2006 - 10:02 PM
- Back to top
I don't know either, but maybe each newly created window's unique ID number tends to be greater than those of previous windows. If that turns out to be true, you could use it if there's no better way.
#2 - Posted 05 January 2006 - 02:26 AM
- Back to top
I found one relevant function while wandering the halls of Windows. You can use GetProcessTimes (with NT 3.5+) to determine process creation time.
#3 - Posted 05 January 2006 - 03:06 AM
- Back to top
Found the function:
http://msdn.microsof... ... stimes.asp
I've had a go at it, but not getting any data back - although the errorlevel and result are both 0, so not quite sure what's up - still rather new to all this stuff
As an example, trying to get the info for Calculator:
lpCreationTime = lpExitTime = lpKernelTime = lpUserTime = Winget, pid, PID, Calculator Result := DllCall("GetProcessTimes", "UInt", pid, "Str *", lpCreationTime, "Str *", lpExitTime, "Str *", lpKernelTime, "Str *", lpUserTime) listvars msgbox %Result%
#4 - Posted 05 January 2006 - 07:57 PM
- Back to top
There is another post which demonstrates using OpenProcess to obtain the process handle.
h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid )
And a post which demonstrates using GetSystemTimes, which requires similar parameters as GetProcessTimes.
success := DllCall( "kernel32.dll\GetSystemTimes", "uint", &%p_IdleTime%?ticks, "uint", 0, "uint", 0 )
note: it may be possible to use "int64*", ticks
#5 - Posted 05 January 2006 - 10:41 PM
- Back to top
Hi,
i've tried the same:
WinWait, Rechner AllAcc := 0x10|0x400 Winget, pid, PID, Rechner PIDHandle := DllCall("OpenProcess", "uint", 0x10|0x400, "int", false, "uint", pid) Result := DllCall("GetProcessTimes", UInt, PIDHandle, "int64 *", lpCreationTime, "int64 *", lpExitTime, "int64 *", lpKernelTime, "int64 *", lpUserTime, "Cdecl int") listvars msgbox %lpCreationTime% - %lpExitTime% - %lpKernelTime% - %lpUserTime% return
result: AllAcc[4 of 6]: 1040 ErrorLevel[1 of 1]: 0 lpCreationTime[18 of 63]: 127809685789912368 lpExitTime[1 of 1]: 0 lpKernelTime[8 of 63]: 46266528 lpUserTime[7 of 63]: 6809792 pid[3 of 6]: 344 PIDHandle[2 of 6]: 92 Result[1 of 1]: 1
Kernel & Usertime is working, but Creationtime has some strange values, but it's an point to continue
#6 - Posted 05 January 2006 - 11:34 PM
- Back to top
Creationtime has some strange values
Consider that CreationTime is:
a point in time expressed as the amount of time that has elapsed since midnight on January 1, 1601 at Greenwich, England.
#7 - Posted 06 January 2006 - 12:26 AM
- Back to top
Hi Shimanov,
i've considered that, but the value doesn't change. Even if there are lot's of seconds gone by since 1601 the value should change sometimes :-)
#8 - Posted 06 January 2006 - 01:21 AM
- Back to top
the value doesn't change
So it's not strange, but constant. Do you observe a different CreationTime for different processes?
#9 - Posted 06 January 2006 - 01:28 AM
- Back to top
:shock: :oops: ouch that hurts.
I should think before I write something stupid. Of course it never changes, since it's the creation time.... not a "difference-time"
To have a lame excuse: It's 2 o'clock in the morning here :-)
Ciao
Micha
#10 - Posted 06 January 2006 - 01:31 AM
- Back to top
It's 2 o'clock in the morning here :-)
I can appreciate that.
I noticed one other problem with the syntax of your call to GetProcessTimes. This function is not defined with a "cdecl" calling convention.
And to start your morning... some functions to facilitate conversion from ticks count to something more conventional:
FileTimeToLocalFileTime
FileTimeToSystemTime
#11 - Posted 06 January 2006 - 02:24 AM
- Back to top
I'd been working on this separately and just noticed all the activity here :lol:
This seems to be working although I would be amazed if it can't be improved upon (and probably amazing it works at all given the amount of trial and error involved hehe).
Winget, p_pid, PID, Calculator ; PROCESS_VM_READ = 0x0010 , PROCESS_QUERY_INFORMATION = 0x0400 h_process := DllCall( "OpenProcess", "uint", 0x10|0x400, "int", false, "uint", p_pid ) Result := DllCall("kernel32.dll\GetProcessTimes", "uint", h_process, "uint", &lpCreationTime, "uint", 0, "uint", 0, "uint", 0) Result := DllCall("kernel32.dll\FileTimeToSystemTime", "uint", &lpCreationTime, "uint", &lpCreationTimeUTC) lpCreationTimeUTC_year := ReadInteger( &lpCreationTimeUTC, 0, 2 ) lpCreationTimeUTC_month := ReadInteger( &lpCreationTimeUTC, 2, 2 ) lpCreationTimeUTC_day := ReadInteger( &lpCreationTimeUTC, 6, 2 ) lpCreationTimeUTC_hour := ReadInteger( &lpCreationTimeUTC, 8, 2 ) lpCreationTimeUTC_min := ReadInteger( &lpCreationTimeUTC, 10, 2 ) lpCreationTimeUTC_sec := ReadInteger( &lpCreationTimeUTC, 12, 2 ) listvars msgbox, Created on: Year: %lpCreationTimeUTC_year% , Month: %lpCreationTimeUTC_month% , Day : %lpCreationTimeUTC_day% , Hour: %lpCreationTimeUTC_hour% , Min: %lpCreationTimeUTC_min% , Sec: %lpCreationTimeUTC_sec% return ReadInteger( p_address, p_offset, p_size ) { value = 0 loop, %p_size% value := value+( *( ( p_address+p_offset )+( a_Index-1 ) ) << ( 8* ( a_Index-1 ) ) ) return, value }
#12 - Posted 06 January 2006 - 03:17 AM
- Back to top
#13 - Posted 29 December 2006 - 10:39 PM
- Back to top
Source: https://www.autohotkey.com/board/topic/6647-window-or-process-creation-time/
Post a Comment for "Create a Window in Autoit That Updates as Process Continues"