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

NEed help

Status
Not open for further replies.

lalee5

Technical User
Oct 20, 2002
70
US
I am writing a time clock program. I don't want the user to be able to change the system date and time. Is there a way to restrict this?

Also Can I compare the date and time to the last punch in. For expamle if time or date is less than last person punch in then system gives error.

if so , How do I compare date and time. I try to use timenow.text<timelast.text and it did not work.




Kay
 
check out the datediff function, to restrict access to the clock you should check into using Windows security.

Also, please have a look at faq222-2244
 
I just wrote one myself and I retrieve the time from a server and use that time. If the user changes the time on the pc, it will make no difference.
Here's the code I use, just paste into a module.

Option Explicit

Private Declare Function NetRemoteTOD Lib "Netapi32.dll" _
(tServer As Any, pBuffer As Long) As Long

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Type TIME_ZONE_INFORMATION
Bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type

Private Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long

Private Declare Function NetApiBufferFree Lib "Netapi32.dll" _
(ByVal lpBuffer As Long) As Long

Private Type TIME_OF_DAY_INFO
tod_elapsedt As Long
tod_msecs As Long
tod_hours As Long
tod_mins As Long
tod_secs As Long
tod_hunds As Long
tod_timezone As Long
tod_tinterval As Long
tod_day As Long
tod_month As Long
tod_year As Long
tod_weekday As Long
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal Length As Long)


Public Function GetServerTime() As String

Dim result As Date
Dim lRet As Long
Dim tod As TIME_OF_DAY_INFO
Dim lpbuff As Long
Dim tServer() As Byte

tServer = "\\PUMPS" & vbNullChar
lRet = NetRemoteTOD(tServer(0), lpbuff)

If lRet = 0 Then
CopyMemory tod, ByVal lpbuff, Len(tod)
NetApiBufferFree lpbuff
result = TimeSerial(tod.tod_hours, tod.tod_mins - tod.tod_timezone, tod.tod_secs)
GetServerTime = Format(result, "Short Time") 'Return the time in 24 hr format
Else
Err.Raise vbObjectError + 1001, "Server Time", "Unable to get Server Time"
End If

End Function
 
I have used that approach in the past and have had issues with having to reboot the server on which I get the time from. I do not reccommend doing that because if the server fails then you're entire timeclock system is not working...

I would use something similar to Active Directory to restrict access to the clocks and have each computer synch it's clock with a domain controller.
 
In our environment, if the server fails, then all the apps fail. I get the time from the server that has the data on it.
 
Zakron4,

I paste the code in a new module. Ran the programe and it is giving me an error:


Can't find dll entry point netremoteTOD in Netapi32.dll


What does that mean? and do I replace "PUMPS" with our server name?


Kay
 

Yes, that would be the server that your getting the time from.
 
Zarkon4,

Still getting the same message after I replace the server name.


Can't find dll entry point netremoteTOD in Netapi32.dll


kay
 

Check your system32 directory for the Netapi32.dll.
I'm not sure about what I'm about to say, it sounds like networking is not installed on it.
I've not tried the code on Win ME, but I do know it works on 2000 and NT.
 

I would suggest upgrading your operating system, in my experience WIN ME has no place in a business environment.
Only my opinion.
 
I would agree with zarkon4 on this issue. You will not want to be running an application as critical as your time clocks on a windows 9x/ME platform. Zarkon's code will unfortunately not run on anything other than NT based OS's.
 
Hi zarkon4,
It took me awhile to get back to this. I updated my OS to Windows 2000 professional. Ran the program but it says unable to get server time???

it is in your code, what do I need to do to get it to get server time?


Kay
 
The variable tServer has \\PUMPS, replace this with
your server name.
 
below is what I have:


tServer = "\\Marble" & vbNullChar



Still says unable to get time from server



Kay
 
I don't know what the problem would be, I use the domain server and have not tried it on any other server. Are you using a domain server?
 
I have just tried it on several different servers and have not had a problem. You may want to check your security policies to ensure that users are able to retrieve the time from the server. This is the only other thing I can think of. I believe it is in the local or group policy on the server you are trying to get the time from.
 
lalee,
IF there is an error the NetRemoteTOD call should return an
error code. I beleive the Windows Time service on the server should also be started.
Here is a link for the error codes.

set a break point after this line
lRet = NetRemoteTOD(tServer(0), lpbuff)
then check the value of lRet with the following.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top