Solved

GET SERVER TIME..

Posted on 1998-03-25
3
203 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

705 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

18 Experts available now in Live!

Get 1:1 Help Now