Solved

Close program after period of inactivity

Posted on 2012-04-10
8
1,104 Views
Last Modified: 2012-06-21
In my business i potentially have instances of my program open on various networked computers.  I would like to have the instances "Time out" if there was no keyboard or mouse activity after a certain period of time, say 15 or 30 minutes and return the program back to the login screen.  Keep in mind i need it as simple as possible (i'm a still a bit of a newbie).

Unfortunately i don't like the new experts exchange website and find it hard to search for just foxpro solutions. (Maybe someone can also clue me in on how to do that more easily).

Sincerely,
Dean
0
Comment
Question by:phantomcom
  • 5
  • 3
8 Comments
 
LVL 41

Expert Comment

by:pcelba
ID: 37829774
Bryan_123 posted a piece of code (http://www.experts-exchange.com/Microsoft/Applications/FoxPro/Q_21053578.html) which you can use in a timer to determine the last user input and do appropriate action:
CLEAR

Local iTime As Integer, iLast As Integer
Local plii As String, cLast As String

Declare Integer GetTickCount In kernel32
Declare Short GetLastInputInfo In win32API String @ plii

DO WHILE .t.
iTime      = GetTickCount()
plii      = Chr(8) + Replicate(Chr(0), 7)
cLast      = GetLastInputInfo(@plii)
iLast      = (Asc(Substr(plii, 8, 1)) * 16777216) + ;
(Asc(Substr(plii, 7, 1)) * 65536) + ;
(Asc(Substr(plii, 6, 1)) * 256) + ;
Asc(Substr(plii, 5, 1))

TotTime=(m.iTime - m.iLast) / 1000

*? m.iTime, m.iLast, totTime
? "Inactivity TIME:", totTime, "s"

lcKey=INKEY(0.5)
IF lcKey = 27  && Esc key
  EXIT
ENDIF

ENDDO

Open in new window

0
 
LVL 41

Expert Comment

by:pcelba
ID: 37829779
To answer your second question: use Google to search EE.
0
 

Author Comment

by:phantomcom
ID: 37829958
Should i place the above code on the click event of my login form?

Dean
0
 
LVL 41

Expert Comment

by:pcelba
ID: 37830015
No, not at all. The code is just an example how the idle time is calculated and you may use this code in Command window.

To incorporate the main part of the code (without the DO WHILE loop) into your application you should find the right place where you may define e.g. the timer.

You should check the inactivity time in the Timer event and if the inactive time is long enough then you should log the user out and display the login form.

The timer should be created on a form which is still active or visible or exists at least. It can even be the main FoxPro window referenced by _screen variable.

Implementation details depend on your app architecture.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:phantomcom
ID: 37832476
i added the timer object to the most appropriate form. I changed the interval within the timer object to 20000 milliseconds just for testing purposes. Do i now place the above code in the timer procedure? (Remember i'm a bit of a newbie still).

Here's what i added under the timer procedure:

CLEAR

Local iTime As Integer, iLast As Integer
Local plii As String, cLast As String

Declare Integer GetTickCount In kernel32
Declare Short GetLastInputInfo In win32API String @ plii

iTime      = GetTickCount()
plii      = Chr(8) + Replicate(Chr(0), 7)
cLast      = GetLastInputInfo(@plii)
iLast      = (Asc(Substr(plii, 8, 1)) * 16777216) + ;
(Asc(Substr(plii, 7, 1)) * 65536) + ;
(Asc(Substr(plii, 6, 1)) * 256) + ;
Asc(Substr(plii, 5, 1))

TotTime=(m.iTime - m.iLast) / 20000

*? m.iTime, m.iLast, totTime
? "Inactivity TIME:", totTime, "s"

lcKey=INKEY(0.5)
IF lcKey = 27  && Esc key
  EXIT
ENDIF

Pretty much the same as the above code. After 20 seconds the cursor disappears but nothing else happens. If i move the mouse the cursor reappears.

What's next to get this to work.

Dean
0
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 37833626
You are closer now.

The declaration part should be executed just once so you should place the following commands into your app startup part:

Declare Integer GetTickCount In kernel32
Declare Short GetLastInputInfo In win32API String @ plii

Timer event should contain following code:
Local iTime As Integer, iLast As Integer
Local plii As String, cLast As String, totTime

iTime      = GetTickCount()
plii      = Chr(8) + Replicate(Chr(0), 7)
cLast      = GetLastInputInfo(@plii)
iLast      = (Asc(Substr(plii, 8, 1)) * 16777216) + ;
(Asc(Substr(plii, 7, 1)) * 65536) + ;
(Asc(Substr(plii, 6, 1)) * 256) + ;
Asc(Substr(plii, 5, 1))

TotTime=(m.iTime - m.iLast) / 1000  && this constant must remain 1000

IF m.totTime > 20  && test for 20 secs 
  *-- Actions when the code waits longer than 20 sec
  THIS.Enabled = .F.  && Disable the Timer
  WAIT WINDOW "Inactive longer than 20 sec ... QUIT in 3 secs" TIME 3
  QUIT
ELSE
  WAIT WINDOW "Inactive " + TRANSFORM(m.totTime) + " sec" NOWAIT
ENDIF

Open in new window


To better see what's hapenning you may set the Timer.Interval to 1000 ms. You have to write your own code in at the end of the above code sample. The interval in the real application can be e.g. 5 minutes - no need to check inactivity every minute.

The Timer can remain disabled when no user is logged in. If the user logs in then you may enable the Timer by setting its Enabled property to .T.:

YourForm.YourTimer.Enabled = .T.
YourForm.YourTimer.Interval = ...
0
 

Author Comment

by:phantomcom
ID: 37835526
Horray! It appears to work. Just to make sure i understand correctly the "IF m.totTime > 20" the 20 is seconds so at this point if i want it to wait 15 minutes before timeout i would set it for 900 seconds.

Currently the code shuts down (quits) the whole program. How can i get it to close the current form and return to the login screen which is login.scx.
0
 
LVL 41

Expert Comment

by:pcelba
ID: 37836327
Yes, 900 is 15 minutes.
To answer your question how to display the login screen is more difficult because it depends on your app architecture. You'll probably need to log the current user off, so you have to call the routine used for log-off process. Then you may display the log-in form as you do when the application starts. The simplest command is "DO FORM login" but each application handles the form creation in a different way so you will need to study your code a bit.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now