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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing System Clock 2

Status
Not open for further replies.

vpaladan

Programmer
Nov 13, 2002
13
PH
Hi

Does anybody know how to limit the user on changing the System clock while the database program is running.

I'm planning to use a computer as an office in/out clock.

Thanks

Vic
 
vpaladan

There is most likely an API call to lock access to the Date/Time dialog box , but you could also use a program that resets the time every minute (depending on your internet access). There are a lot of those on the internet (The one I use is called Atomic Clock). Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
If they don't have Internet access, an alternative is to check/set the workstation's time based on the network server's time. The server is likely not as accessable (or shouldn't be!) as the workstations. (Note: I've got some code that works to do - this if you want it.)

Of course this solution or one that uses Profiles to prevent access to the Date/Time Dialog does require more than a simple one station configuration.

Rick
 
Rick, I would love to see the code for the network server as our time base!

Frank
 
Frank,
Here you go. I did some minor modifications to make it "generic", but this seems to work just fine on Win95 -> WinXP workstations, with NT, 2000, and Novell file servers.
Usage:
Code:
* Check Time
? "Current Time on Server: " + ttoc(settime("W:\rgb", .T.))

* Set Workstation Time to Server Time
IF NOT settime("W:\rgb") && failed to set
   Messagebox("OOPs!")
ENDIF
Rick
Code:
* Program....: SETTIME.PRG
* Author.....: ** Richard G Bean **
* Date.......: May 10, 2001
* Compiler...: Visual FoxPro 06.00.8961.00 for Windows
* Parameters:
*          p_cServerDataPata - Provide a Path to the Data Server where we can write a temp file
*          p_lJustGetServerTime - .T. -> just return the server Time, .F. -> Set Workstation to this time
*
*

LPARAMETERS p_cServerDataPata, p_lJustGetServerTime
LOCAL l_tWSCurrent, l_pTimeSet, l_nRetVal, l_nLastError, l_cBuffer

IF PCOUNT() < 2 OR VARTYPE(p_lJustGetServerTime) <> &quot;L&quot;
   p_lJustGetServerTime = .F.
ENDIF

LOCAL l_cTempFileName, l_nFileHndl, l_nFound, tod_month, tod_day, tod_year, tod_hours, tod_mins, tod_secs
LOCAL serverdatetime, l_pTimeSet, l_nRetVal, l_nLastError

l_cTempFileName = SYS(2015) && Unique Procedure Name
l_cTempFileName = ADDBS(p_cServerDataPata) + l_cTempFileName + &quot;.$$$&quot;
l_nFileHndl = FCREATE(l_cTempFileName)
IF l_nFileHndl < 0     && Check for error opening file
   RETURN .F.
ENDIF
=FCLOSE(l_nFileHndl)     && Close file
l_nFound = ADIR(l_aInfo, l_cTempFileName)
IF l_nFound <> 1
   RETURN .F.
ENDIF
DELETE FILE (l_cTempFileName)

tod_month = MONTH(l_aInfo[3])
tod_day = DAY(l_aInfo[3])
tod_year = YEAR(l_aInfo[3])
tod_hours = INT(VAL(SUBSTR(l_aInfo[4], 1, 2)))
tod_mins = INT(VAL(SUBSTR(l_aInfo[4], 4, 2)))
tod_secs = INT(VAL(SUBSTR(l_aInfo[4], 7, 2)))

serverdatetime = DATETIME(tod_year, tod_month, tod_day, ;
   tod_hours, tod_mins, tod_secs)

IF p_lJustGetServerTime
   RETURN serverdatetime
ENDIF

* Set the Local Time and Date

* First check local to see if it's worth changing

l_tWSCurrent = datetime()
IF ABS(serverdatetime - l_tWSCurrent) < 16 && close enough - avoid the overhead
   RETURN .T.
ENDIF

l_pTimeSet = &quot;&quot; ;
   + word2str(tod_year);
   + word2str(tod_month);
   + word2str(1);
   + word2str(tod_day);
   + word2str(tod_Hours);
   + word2str(tod_Mins);
   + word2str(tod_Secs);
   + word2str(0)
 		
Declare INTEGER SetLocalTime in kernel32 STRING
l_nRetVal = SetLocalTime(l_pTimeSet)

IF l_nRetVal = 0 && Error
   DECLARE INTEGER GetLastError in Kernel32
   l_nLastError = GetLastError()
   Declare Integer FormatMessage in kernel32 Long, Long, Long, Long, String, Long, Long
   #DEFINE FORMAT_MESSAGE_FROM_SYSTEM  0x1000
   #DEFINE LANG_NEUTRAL 0x0

   l_cBuffer = replicate(chr(0), 201)
   = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, ;
       l_nLastError, LANG_NEUTRAL, @l_cBuffer, 200, 0)
   l_cBuffer = ALLTRIM(STRTRAN(l_cBuffer, chr(0),&quot;&quot;))
   messagebox(l_cBuffer, 0, &quot;Please Note&quot;)
   RETURN .F.
ENDIF

* Use SendMessage to tell everybody that we've changed the system time.
DECLARE INTEGER SendMessage IN win32api ;
   INTEGER WindowHandle, ;
   INTEGER MESSAGE, ;
   STRING Param1, ;
   STRING Param2

* SendMessage constants.
#DEFINE HWND_BROADCAST 65535
#DEFINE WM_TIMECHANGE 30

* Send the message that the time has changed.
= SendMessage(HWND_BROADCAST, WM_TIMECHANGE, &quot;&quot;, &quot;&quot;)

RETURN .T.

*************************************************************
FUNCTION word2str
*************************************************************
* passed:  integer value
* returns:  2-byte character string (m.longstr) in low-high ASCII format
* example:
*	m.wordval = 111
*	m.wordstr = word2str(m.wordval)

LPARAMETERS p_nWordval

PRIVATE l_nii, l_cRetval

l_cRetval = &quot;&quot;
FOR l_nii = 0 to 1
   l_cRetval = l_cRetval + CHR(p_nWordval % 256)
   p_nWordval = int(p_nWordval / 256)
NEXT
RETURN l_cRetval

*!* EOP: SETTIME.PRG
 
Mike,

Your First suggestion is the best solution to the problem. Do you have sample code? Atomic clock will not work because of internet connection problem.

Again, Thank you very much.

Vic
 
vpaladan

Your First suggestion is the best solution to the problem. Do you have sample code? Atomic clock will not work because of internet connection problem.

Sample code for what?
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

Sample code for an API Call to lock access (or password protect)to the Date/Time dialog box.

Thanks in advance

Vic
 
vpaladan

I suggested there is probably an API call to lock it out, but I don't have it and I do not recommend you try to control the Windows setting through VFP. In my opinion that is not the purpose of VFP. But if you have users the like to play around with the system clock, you could:
[ol][li]Srink the taskbar so it is out of the way[/li]
[li]If you go to Winzip.com there is a program that would help you control pretty much everything in Windows, add password protection on pretty much all windows components. The file is called RegSpanner.[/li]
[li]Edit the registry (not recommended) to remove the clock from the taskbar.[/li]
[li]Or hire employees that do not play with the system clock ;-)[/li][/ol]
Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
vpaladan

If you go to Winzip.com there is a program that would help you control pretty much everything in Windows, add password protection on pretty much all windows components. The file is called RegSpanner.

Sorry I made mistake, the Regspanner is located here.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
vpaladan,

Something I have done in the past was to locate the file:
timedate.cpl
and remove it or rename it. Without that Control Panel file, the &quot;Date/Time Properties&quot; dialog won't run.
Dave S.
 
If everyone is clocking in on the same computer (same PC), you could use Win2000 and if the priviledges are less than a 'Power User', then the pc clock cannot be accessed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top