Solved

GET SERVER TIME..

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

808 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