GET SERVER TIME..

How can I get the a server's time from a client PC in VB? I am using WinNT as server and windows95/winnt as client...
LVL 1
LCPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abelCommented:
For 50 points? OK, since the solution is quite easy and I did the hard part before, here it goes:
(If you want to view the whole discussion, go to my customer info and select the question "Synchronizing Clocks")

For WinNT server/client you can use NetRemoteTOD (see below) for W95 you must use a DOS statement:

NET TIME \\computername /SET /YES

This does asking the time AND synchronizing the clock at once. Call it in a hidden DOS-window, so the users of your program won't see what's happening.


NetRemoteTOD and TIME_OF_DAY_INFO
------------------------------------------------------------
This function does not work on Windows 95 (and you won't find them in the API-veiwer as well)!
Here is the declaration for the function and the definition of the type. Somehow on my computer I only get the tod_elapsedt value set. If you have the same problem you'll have to compute the time from that value. It specifies the number of seconds since 00:00:00, January 1, 1970.

NOTE: you must use unicode strings, so use the function StrConv("CompName", vbUnincode) to get the right string.
NOTE: Precede your Computername with two backslashes.

Example:
Ret = NetRemoteTOD(StrConv("\\MyCompName", vbUnicode), TOD)

If Ret <> 0 then ERROR


'The declarations
'-----------------------

Type TIME_OF_DAY_INFO
    tod_elapsedt As Long
    tod_msecs     As Long
    tod_hours       As Long
    tod_mins        As Long
    tod_secs        As Long
    tod_hunds      As Long
    tod_timezone As Long
    tod_tinterval   As Long
    tod_day          As Long
    tod_month      As Long
    tod_year         As Long
    tod_weekday As Long
End Type

Declare Function NetRemoteTOD Lib "netapi32" (ByVal UncServerName As String, BufferPtr As TIME_OF_DAY_INFO) As Long
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
LCPAuthor Commented:
Thx a lot!
But my VB program will be used in WinNT and Win95 as well,
so... is there any solution can solve both with the same program code?
0
abelCommented:
You can do that by checking on the version of windows before you start getting the time. For Win95 you'll have to use NET TIME \\computername for it. It's a shame that Win95 didn't include NetRemoteTOD and that you have to use this workaround. Another solution can be using RPC, but that's another story and as far as I know, you can only use that in conjunction with a dll (or exe if you prefer) made in C, so I don't think that's optional.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.