Updating PC Date/Time via WinAPI 
Author Message
 Updating PC Date/Time via WinAPI

Is it possible to update a PCs Date and Time settings,
using WinAPI, with the Date and Time from a Windows NT
server.

I currently access the Date and Time of the NT server
using the getdate() function in SQL Server which is
running on that server. I would be altering the Date/Time
settings using this Pass-Through query via a WinAPI
command (if there is one).

Or if there is a better solution then what I am planning
then so much the better.

Thanks

NJ Smith AMIAP



Wed, 30 Jun 2004 01:17:18 GMT  
 Updating PC Date/Time via WinAPI
Yes, you can. I don't have an API book here to tell you how.

Something else that works though if the server is set to the same time zone
and time as the workstation is the Shell command.

Ex.
Dim RetVal as Variant
RetVal=Shell("command.com /c net time \\server /set /yes", vbHide)

Go to a command prompt and type Net Time /? and see if there are other
switches that you may need for your situation.

Wayne Morgan


Quote:
> Is it possible to update a PCs Date and Time settings,
> using WinAPI, with the Date and Time from a Windows NT
> server.

> I currently access the Date and Time of the NT server
> using the getdate() function in SQL Server which is
> running on that server. I would be altering the Date/Time
> settings using this Pass-Through query via a WinAPI
> command (if there is one).

> Or if there is a better solution then what I am planning
> then so much the better.



Wed, 30 Jun 2004 15:40:02 GMT  
 Updating PC Date/Time via WinAPI
Quote:
>Yes, you can. I don't have an API book here to tell you

how.

Thanks. Found the answer:

<--- 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
'

Public Sub SetDate()
  Dim lpSystemTime      As SYSTEMTIME
  Dim datDate           As Date

  datDate = #1/19/2001 11:59:59 PM#     'Alter to a
Dlookup Statement

  lpSystemTime.wYear = Format(datDate, "yyyy")
  lpSystemTime.wMonth = Format(datDate, "mm")
  lpSystemTime.wDay = Format(datDate, "dd")
  lpSystemTime.wHour = Format(datDate, "hh")
  lpSystemTime.wMinute = Format(datDate, "nn")
  lpSystemTime.wSecond = Format(datDate, "ss")
  lpSystemTime.wMilliseconds = 0

  'set the new time
  SetSystemTime lpSystemTime
End Sub
<--- END CODE --->



Fri, 02 Jul 2004 17:05:49 GMT  
 Updating PC Date/Time via WinAPI
Also have a look at Gary Gibson's site www.grc.com where he has a very neat
solution for synchronising the server and network clients to atomic clocks.
Cheers
Terry


Quote:
> Is it possible to update a PCs Date and Time settings,
> using WinAPI, with the Date and Time from a Windows NT
> server.

> I currently access the Date and Time of the NT server
> using the getdate() function in SQL Server which is
> running on that server. I would be altering the Date/Time
> settings using this Pass-Through query via a WinAPI
> command (if there is one).

> Or if there is a better solution then what I am planning
> then so much the better.

> Thanks

> NJ Smith AMIAP



Sun, 04 Jul 2004 21:01:34 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Compare date in form with date/time in form with date/time in database

2. Updating the PC time.

3. PC Time Update From Internet

4. VB to update body with time stamp via cmd_click

5. Determining file date-time stamp via HTTP

6. Getting File Date/Time via FTP

7. Setting System Date/Time via emVB3

8. No errors on development PC, Run-time on user PC

9. Matching system date/time with field date/time

10. combining a time and a date to one Date/Time value

11. start date/time, end date/time problem

12. How to subtract a date-time from a date-time

 

 
Powered by phpBB® Forum Software