Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto Login/Logoff of date/time in VFP 1

Status
Not open for further replies.

torturedmind

Programmer
Jan 31, 2002
1,052
PH
Hi all! I would just like to ask - how can i log the
date and time of shutdown of a PC to a FoxPro table?
The program is supposed to work in the background and
needs to know when the PC is turned on and when it is
off, and thus, needs to be started/terminated
automatically during startup/shutdown. I'm working under
Win98SE and VFP 6.0, if that makes any difference.

Thnx in adnvance.

EMC (torturedmind)
 
HI
Instead of using VFP, can you think of using the scheduler ?. Could be easier to handle that way.
:) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
EMC,
Startup is the easier of the two. You would simply need to do a quick fox program that writes the date & time to a datetime field. You can do that by creating a table with:
FIELD TYPE/Size
STARTUP Date/time
SHUTDOWN DATE/TIME

Name the table: STRTSTOP.DBF

Then a piece of code which you would execute by putting the program in the windows "Startup".

USE STRTSTOP
APPEND BLANK
REPLACE STARTUP WITH DATE()

The shutdown is a bit trickier. I'm not sure how to detect the windows "Shutdown" function. Also, if a machine is simply "Switched off", you won't be able to detect this, and write to the table. Also, power outages will be a problem. If you can detect the user requested "Shutdown" task (don't know where to start looking) the code that would need to execute is very simple also, and would be:

USE STRTSTOP
GO BOTTOM
IF EMPTY(SHUTDOWN)
REPLACE SHUTDOWN WITH DATE()
ENDIF

I put this IF in, in the event that for some unkown reason there was a problem writing the "Start" time. This will keep you from overwriting an otherwise valid value. Potential, your data would look like this:

Startup Shutdown
1/1/2002 08:00:35 1/1/2002 17:00:01
1/2/2002 08:13:22
1/3/2002 08:10:12
1/4/2002 09:00:05 1/5/2002 17:35:02

The above would mean:
1) Turned on at 8:00am, turned off at 5:00pm
2) Turned on at 8:13am, but powered off without shutdown
3) Turned on at 8:10am, but powered off without shutdown
4) Turned on at 9:00am, left running all night, turned off at 5:35pm the NEXT day.

Thanks,
-Scott

s-) Please let me know if this has helped s-)
 
It seems to me that there's some sort of event logging that windows itself does or can be made to do, or perhaps it's only certain virus checkers and the like. But anyway, if there's logging somewhere on the system, perhaps you could write a routine to read the requisite entry.

Dave Dardinger
 
You could maybe have a little app that adds a record upon startup which updates the startup time. Then the app could run continuously with a timer firing every minute or so that updates the shutdown or running time. When the app is terminated by windows closing, the record would no longer be updated thereby giving you the shutdown time. At startup, a new record would again be created and so on.

Dave S.
 
thnx for all ur response. im already halfway my code.
my real problem is whenever Windows shuts down, my app,
which is still running in the background, won't quit.
an error "Cannot quit Foxpro!" message appears and
Windows will not shutdown. How can Windows quit my app
automatically? Or is there any registry that i can tinker
with inside my app so that when my app detects that
Windows is abt to shutdown, it will quit itself?
thnx u guys, ur really a big help :)
 
EMC
I haven't tried this, but you might try setting the following in your Main.Prg (whatever you are calling it):

ON SHUTDOWN DO CANCEL

I just don't know if SHUTDOWN will detect a Windows shutdown or not...

Thanks,
-Scott

s-) Please let me know if this has helped s-)
 
hey scott it worked! i didn't know there's a
"ON SHUTDOWN" command. my sincerest gratitude man.
and to all of u guys, many thnx. i think i'll be
visiting this site often. :D

EMC
(Philippines)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top