Skip to content Skip to sidebar Skip to footer

Create a Window in Autoit That Updates as Process Continues

  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005

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.

  • Back to top

Chris

  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

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.

  • Back to top

shimanov

  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

I found one relevant function while wandering the halls of Windows. You can use GetProcessTimes (with NT 3.5+) to determine process creation time.

  • Back to top

evl

  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005

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%            

  • Back to top

shimanov

  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

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

  • Back to top

Micha

  • Members
  • 539 posts
  • Last active: Dec 31 2011 01:43 PM
  • Joined: 15 Nov 2005

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

  • Back to top

shimanov

  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

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.


  • Back to top

Micha

  • Members
  • 539 posts
  • Last active: Dec 31 2011 01:43 PM
  • Joined: 15 Nov 2005

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 :-)

  • Back to top

shimanov

  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

the value doesn't change

So it's not strange, but constant. Do you observe a different CreationTime for different processes?

  • Back to top

Micha

  • Members
  • 539 posts
  • Last active: Dec 31 2011 01:43 PM
  • Joined: 15 Nov 2005

: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

  • Back to top

shimanov

  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

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

  • Back to top

evl

  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005

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  }            

  • Back to top

SKAN

  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

kWo4Lk1.png

  • Back to top

weirphey1937.blogspot.com

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"