Change System Date/Time in vba without Admin Privileges

BiigJiim

Registered User.
Local time
Today, 11:56
Joined
Jun 7, 2012
Messages
114
Hi,

I have an Access 2010 application running on Win 7 Pro which connects to a Back End SQL Server database. I am trying to get Access to synchronise the client pc system date & time with the Sql server date and time. Please note, the date/time does not necessarily have to be correct, it just has to be consistent between the server and all the pcs running the Access application.

I have tried two methods as follows. But both only work if Access with Administrator privileges, which isn't really practical. Does anyone know of another way or a way around this?

Thanks for any help!
Jim

Method 1:
Code:
    Dim MyDateTime As Date
    
   [I]'Some Code here to get MyDateTime[/I]
    
    If MsgBox("Change date & time to:" & vbCrLf & vbCrLf & MyDateTime & "?", vbYesNo, "Change") = vbYes Then
        Date = DateValue(MyDateTime)
        Time = TimeValue(MyDateTime)
    End If

Method 2:
Code:
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 Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) As Long

Private Sub Command2_Click()

 Dim lpSystemTime As SYSTEMTIME
 lpSystemTime.wYear = 2000
 lpSystemTime.wMonth = 1
 lpSystemTime.wDayOfWeek = -1
 lpSystemTime.wDay = 24
 lpSystemTime.wHour = 23
 lpSystemTime.wMinute = 26
 lpSystemTime.wSecond = 0
 lpSystemTime.wMilliseconds = 0
 'set the new time
 SetSystemTime lpSystemTime
 
 MsgBox Now

End Sub
 
No you cant change the actual pc time without admin priv.

However why worry about the pc time at all? why not "simply" get the current time from the sql server... or take note of the server time vs pc time every so often and compensate for it dynamicaly in your database by simply storing the diff in a public variable.
Then if you want the "proper" server time:
Now() + DiffVariable
Should show the proper server time.
 
No you cant change the actual pc time without admin priv.

However why worry about the pc time at all? why not "simply" get the current time from the sql server... or take note of the server time vs pc time every so often and compensate for it dynamicaly in your database by simply storing the diff in a public variable.
Then if you want the "proper" server time:
Now() + DiffVariable
Should show the proper server time.

Thanks Namliam - excellent idea. I should have thought of that myself!
 

Users who are viewing this thread

Back
Top Bottom