attribute - creation date

attribute - creation date

Postby Natter » Fri Nov 08, 2024 3:49 pm

Hi,

I need to detect the appearance of some window on the screen. For this purpose I use EnumChildWindows.
Do the checked windows (or the processes that created them) have an attribute - creation date ?
Natter
 
Posts: 1218
Joined: Mon May 14, 2007 9:49 am

Re: attribute - creation date

Postby TomH » Wed Nov 20, 2024 6:58 am

The EnumChildWindows function itself does not provide direct access to the creation date of the windows it enumerates.
I obtained the following information through perplexity.ai

a simplified example in C

Code: Select all  Expand view

#include <windows.h>
#include <stdio.h>

void GetProcessCreationTime(HWND hwnd) {
    DWORD processId;
    // Get the process ID of the window
    GetWindowThreadProcessId(hwnd, &processId);
   
    // Open the process to query information
    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
    if (hProcess) {
        FILETIME creationTime, exitTime, kernelTime, userTime;
       
        // Get the process time information
        if (GetProcessTimes(hProcess, &creationTime, &exitTime, &kernelTime, &userTime)) {
            SYSTEMTIME st;
            // Convert FILETIME to SYSTEMTIME
            FileTimeToSystemTime(&creationTime, &st);
           
            // Output the creation time
            printf("Creation Time: %04d-%02d-%02d %02d:%02d:%02d\n",
                   st.wYear, st.wMonth, st.wDay,
                   st.wHour, st.wMinute, st.wSecond);
        } else {
            printf("Failed to get process times.\n");
        }
       
        // Close the process handle
        CloseHandle(hProcess);
    } else {
        printf("Failed to open process. Error: %lu\n", GetLastError());
    }
}

int main() {
    // Example: Get the creation time of the desktop window
    HWND hwnd = GetDesktopWindow();
    GetProcessCreationTime(hwnd);
   
    return 0;
}
 




Regards,
Tom.H.
TomH
 
Posts: 1
Joined: Tue Nov 12, 2024 1:30 pm

Re: attribute - creation date

Postby Natter » Wed Nov 20, 2024 2:12 pm

Thanks ! I solve this problem like this - request processes of a certain type through WMi and compare them .CreationDate
Natter
 
Posts: 1218
Joined: Mon May 14, 2007 9:49 am

Re: attribute - creation date

Postby Antonio Linares » Wed Nov 20, 2024 2:44 pm

Dear Yuri,

Would you mind to share that code to help other users ?

many thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: attribute - creation date

Postby Natter » Wed Nov 20, 2024 7:22 pm

I check the same type of processes (e.g. Excel) roughly like this:
Code: Select all  Expand view
#INCLUDE "FiveWin.ch"

procedure Main
local  dim:=Lst_Pss("EXCEL.EXE")) //list process
  if len(dim)>0
    atail(dim):CreationDate
 endif
return

FUNCTION Lst_Pss(pss)
local dim:={}
local oList, oProc
** pss - application name

    oWmi:= WmiService()
    oList:= oWmi:ExecQuery( "select * from Win32_Process where Name = '" + pss + "'" )
    for each oProc in oList
      aadd(dim, oProc)
    next
return dim

function WMIService()
local oLocator := CREATEOBJECT( "wbemScripting.SwbemLocator" )
return  oLocator:ConnectServer()
 
Natter
 
Posts: 1218
Joined: Mon May 14, 2007 9:49 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 33 guests