EvilTwin,
Yes, it's possible to do this, though you'll need a utility that shuts down the computer (or logs off the current user). Windows XP provides one with the OS (shutdown.exe can be found in \WINDOWS\SYSTEM32); it's also available for Win 2K/NT4, but you'll need the appropriate Windows Resource Kit from MS to get it. MS documents the resource kit utility at
though you may want to review
for some corrected details.)
Alternatively,
offers a free utility for NT, Win 2K, and XP. (Please note that Win9.x is *not* supported.)
In any event, the basic idea is to either log off the user or to reboot the machine after shutting down (which closes the applications). You can set this up to automatically happen at a set time after the end of the work day but before your automated tasks start. Use either Schedule Tasks or the AT utility (see the MSDN article posted earlier).
Alternatively, Perrin's idea is a good one, e.g. adding code to a form's timer to automatically close the form after a set period of time of inactivity.
Let's define "activity" as a keyboard or mouse event. That done, here's how you can set this up for an individual form:
1. Open your form in Design mode and then declare the following in the form object's Var window:
Code:
Var
tLastAction Time
endVar
2. Open the form's init event and then add the following code:
Code:
method init(var eventInfo Event)
tLastAction = time()
self.setTimer( 1000 )
endMethod
3. Open the form's keyChar event and then add the following code:
Code:
method keyChar(var eventInfo KeyEvent)
if not eventInfo.isPreFilter() then
tLastAction = time()
endIf
endMethod
4. Open the form's keyPhysical event and then add the following code:
Code:
method keyPhysical(var eventInfo KeyEvent)
if not eventInfo.isPreFilter() then
tLastAction = time()
endIf
endMethod
5. Open the form's mouseDown event and then add the following code:
Code:
method mouseDown(var eventInfo MouseEvent)
if not eventInfo.isPreFilter() then
tLastAction = time()
endIf
endMethod
6. Open the form's mouseMove event and then add the following code:
Code:
method mouseMove(var eventInfo MouseEvent)
if not eventInfo.isPreFilter() then
tLastAction = time()
endIf
endMethod
7. Open the form's timer() event and then add the following code:
Code:
method timer(var eventInfo TimerEvent)
var
tIdleTime Time
endVar
if not eventInfo.isPreFilter() then
tIdleTime = ( time() - tLastAction )
if tIdleTime.hour() > 0 then
self.killTimer()
formReturn( FALSE )
endIf
endIf
endMethod
8. Save and run your form.
As you can probably tell, this form essentially does two things:
1. It saves the time of the user's last direct interaction with the form, via the keyboard or the mouse.
2. It starts a timer that compares the current time to the time of the user's last activity. When that exceeds an hour, the form is closed.
There are a few things to keep in mind when using this:
-- Note that I reworked the default code that Paradox normally adds to a form-level event. The main idea is to update the activity time when the form receives a keyboard or mouse event.
-- Paradox doesn't first keyboard events for the Shift, Ctrl, or Alt keys, except when those keys are used in conjunction with other keys on the keyboard. Pressing Shift+A generates an event, but pressing and release Shift doesn't.
-- You can exit Paradox by replacing the self.close() with
exit(); however, be aware that a) if the form has been modified, Paradox will prompt for saving. This is not typically a problem; however, if it becomes a problem, you can clear the DesignModified property to avoid the prompt--just understand that your unsaved changes will be discarded.
Use something like this to clear DesignModified:
Code:
if DesignModified then
DesignModified = FALSE
endIf
-- I used formReturn() to close the form instead of close() in case your form is in a wait() state.
Hope this helps...
-- Lance