Solved

GET SERVER TIME..

Posted on 1998-03-25
3
205 Views
Last Modified: 2008-02-01
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...
0
Comment
Question by:LCP
  • 2
3 Comments
 
LVL 39

Accepted Solution

by:
abel earned 80 total points
ID: 1459733
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
 
LVL 1

Author Comment

by:LCP
ID: 1459734
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
 
LVL 39

Expert Comment

by:abel
ID: 1459735
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now