Set systemtime in win7 with winapi doesn't work:( (1 Viewer)

MBMSOFT

Registered User.
Local time
Today, 19:30
Joined
Jan 29, 2010
Messages
90
I want to set system time with vba code using win apis
I use this code:
Code:
Option Compare Database
Option Explicit
   
Private Declare Function SetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME) 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

Public Function newtime() 

    Dim lReturn As Long
    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
    lReturn = SetSystemTime(lpSystemTime)
    Debug.Print lReturn
exit function
time remain same in win7
lreturn value is 0

i try to do that with
Time = TimeValue("00:00:00")
i got error permission denied

win 7 seems not alows changing systemtime or...
 
Last edited:

JHB

Have been here a while
Local time
Today, 20:30
Joined
Jun 17, 2012
Messages
7,732
Only for info, in Windows 8 the code works.
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 04:30
Joined
Jan 20, 2009
Messages
12,861
I am guessing you are on a domain where the admins have used a Group Policy to prevent the time being changed by users.
 

Users who are viewing this thread

Top Bottom