News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Close program after set period of inactivity

Started by Magnum, November 17, 2010, 12:47:09 AM

Previous topic - Next topic

Magnum

Sinsi,

I will accomplish the goal with learning as the priority.

Have a great day,
                         Andy

Magnum

Quote from: donkey on November 19, 2010, 02:41:00 AM

invoke FindWindow,"MozillaUIWindowClass",NULL
test eax,eax
jz NOFIREFOX ; Firefox was not found or there was an error

; Use SendMessage so we can check the return to see if the message was processed
invoke SendMessage, eax, WM_CLOSE, 0, 0
test eax,eax
jz DONE
; There was an error

DONE:
; Firefox has closed


Not sure what the macro is that you MASM guys use for inline strings, you'll have to figure that out yourself for the class name.

You can also use WaitForSingleObject to make sure it has closed by passing the window handle to that function:

invoke FindWindow,"MozillaUIWindowClass",NULL
test eax,eax
jz NOFIREFOX ; Firefox was not found or there was an error
mov ebx,eax ; Save the window handle
; In this case we'll just post the message since we aren't concerned with the return value
invoke PostMessage, ebx, WM_CLOSE, 0, 0
invoke WaitForSingleObject, ebx, 5000 ; Wait a maximum of 5 seconds
test eax,eax
jz DONE
; There was an error

DONE:
; Firefox has closed

Edgar

Masm complained about invoke FindWindow,"MozillaUIWindowClass",NULL

I can use this to find if it's running.


invoke Process32First,hProcesses,ADDR pe32
    .IF eax
        .WHILE bLoop
            invoke CompareString, LOCALE_USER_DEFAULT, NORM_IGNORECASE, addr pe32.szExeFile, -1, lpszExecutable, -1
            .IF eax==2 ; check if strings are equal in lexical value


I have to plan the order of execution now.

1. Find if FF is running
2. Use my GetLastInputInfo code to watch input activity
3. Figure out which values to subtract to determine when 5 minutes of "user inactivity" have occured
4. Shutdown FF gracefully



Have a great day,
                         Andy