Solved

GET SERVER TIME..

Posted on 1998-03-25
3
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

691 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