Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I searched for codes to change system date but it's not working. What's wrong with this code?


VB
Private Structure SYSTEMTIME
Dim wYear As Short
Dim wMonth As Short
Dim wDayOfWeek As Short
Dim wDay As Short
Dim wHour As Short
Dim wMinute As Short
Dim wSecond As Short
Dim wMilliseconds As Short
End Structure
Private Declare Function SetSystemTime Lib "kernel32" (ByRef lpSystemTime As SYSTEMTIME) As Long

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim timeStru As SYSTEMTIME
timeStru.wDay = 28
timeStru.wDayOfWeek = 6
timeStru.wHour = 21
timeStru.wMilliseconds =203
timeStru.wMinute = 50
timeStru.wMonth = 9
timeStru.wSecond = 35
timeStru.wYear = 2007 'set the new time
SetSystemTime(timeStru)
End Sub



I'm using windows 7 and plans to try it on windows 8. Thanks.
Posted
Comments
CHill60 11-Oct-14 12:00pm    
Does the domain account you are running this under have permissions to change the system date?

1 solution

As CHill60 discusses read the documentation on the call. If you are going to play on the Win32 API at least bother to read the documentation on the calls

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724942%28v=vs.85%29.aspx[^]

Remarks

The calling process must have the SE_SYSTEMTIME_NAME privilege. This privilege is disabled by default. The SetSystemTime function enables the SE_SYSTEMTIME_NAME privilege before changing the system time and disables the privilege before returning. For more information, see Running with Special Privileges.


The function also has error return via GetLastError to confirm the problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900