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

How do I set Windows system time to Real Time Clock?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
How do I set the windows time to the CMOS real time clock without rebooting the computer. As explained in , the windows system time only gets it reference from the real time clock at startup time. You have to query interupt &h1A. I got a routine from ALT255 in qbasic that does it but does anyone know how to do it in VB?
Regards Ted
 
Option Explicit

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 Command1_Click()
Dim lReturn As Long
Dim lpSystemTime As SYSTEMTIME
lpSystemTime.wYear = 1999
lpSystemTime.wMonth = 6
lpSystemTime.wDayOfWeek = 5
lpSystemTime.wDay = 28
lpSystemTime.wHour = 9
lpSystemTime.wMinute = 42
lpSystemTime.wSecond = 0
lpSystemTime.wMilliseconds = 0
lReturn = SetSystemTime(lpSystemTime)
End Sub

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX
 
Sorry thats not what I need. That will set the System time to the values you enter and also set the real time clock to the same.
I need the opposite-
I want to set the Systemtime to the Real time clock without altering the real time clock and without haviong to reboot the computer. The System time is only a software clock, only set at bootup time and it drifts with time over a long period. The real time clock is a xtal like in your watch and is much more accurate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top