?
Solved

Getting the server time

Posted on 2001-06-11
6
Medium Priority
?
212 Views
Last Modified: 2010-05-02
Hi everyone,

I'm working on a project where I need to get the current date/time from an NT server rather than using the local PC system clock (on Windows 95 PC's).  I've seen loads of code for doing the same thing from an NT workstation to an NT server, using NETAPI32.dll but this does not work for Win 95.

Any help gratefully received !

Jules
0
Comment
Question by:JulianDavies
[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
6 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6178033
from planet source code

'**************************************
'Windows API/Global Declarations for :Ge
'     t Windows NT Server Time
'**************************************


Private Type TIME_OF_DAY
    t_elapsedt As Long
    t_msecs As Long
    t_hours As Long
    t_mins As Long
    t_secs As Long
    t_hunds As Long
    t_timezone As Long
    t_tinterval As Long
    t_day As Long
    t_month As Long
    t_year As Long
    t_weekday As Long
    End Type


Private Declare Function NetRemoteTOD Lib "netapi32.dll" (ByVal server As String, buffer As Any) As Long


Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)


Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal Ptr As Long) As Long



'**************************************
' Name: Get Windows NT Server Time
' Description:Returns the time of day fr
'     om a Windows NT workstation or server. A
'     ccounts for time zones. Requires Windows
'     NT.
' By: Matthew Ruffell
'
' Inputs:ServerName [string] = name of t
'     arget server.
'
' Returns:Return the time of day.
'
' Assumes:Requires Windows NT.
'
' Side Effects:Noen.
'
'This code is copyrighted and has' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/xq/ASP/txtCode
'     Id.3792/lngWId.1/qx/vb/scripts/ShowCode.
'     htm'for details.'**************************************



Public Function Get_ServerTime(ByVal strServerName As String) As String
    Dim lngBuffer As Long
    Dim strServer As String
    Dim lngNet32ApiReturnCode As Long
    Dim days As Date
    Dim TOD As TIME_OF_DAY
    On Error Resume Next
    '// Get server time
    strServer = StrConv(strServerName, vbUnicode) '// Convert the server name To unicode
    lngNet32ApiReturnCode = NetRemoteTOD(strServer, lngBuffer)


    If lngNet32ApiReturnCode = 0 Then
        CopyMem TOD, ByVal lngBuffer, Len(TOD)
        days = DateSerial(70, 1, 1) + (TOD.t_elapsedt / 60 / 60 / 24) '// Convert the elapsed time since 1/1/70 to a date
        days = days - (TOD.t_timezone / 60 / 24) '// Adjust For TimeZone differences
        Get_ServerTime = days
    End If
    '// Free pointers from memory
    Call NetApiBufferFree(lngBuffer)
End Function
0
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6179875
Hi!  I don't know if this is applicable, but here's the code:

Download...
http://www.vb-helper.com/Howto/wintime.zip

Description: See how long Windows has been running (2K)

That's it!

glass cookie : )
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6180945
the above I gave you is the only way i know to do this, of course it doesn't work in win 95 which really doesn't help you.  Have you tried installing the netapi.dll on a win 95 machine?  It probably won't work but is worth a try.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

Accepted Solution

by:
Ark earned 800 total points
ID: 6189257
Hi
You can save dummy file on server and get this file time stamp, smth like this:

Const DummyFile = "\\servername\c\dummy.txt"
Open DummyFile for OutPut As #1
Print #1, "Test"
Close #1
ServerTime = FileDateTime(DummyFile)
Kill DummyFile

Cheers
0
 

Author Comment

by:JulianDavies
ID: 6189945
Nice piece of lateral thinking !!! Thanks Ark and thankyou to everyone else who added comments.

Jules
0
 
LVL 28

Expert Comment

by:Ark
ID: 6190098
Thanks for points, glad I could help you
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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