Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Get Time and Date of a Network machine Server or Workstation

Total Hit ( 3159)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Step-By-Step Example

- Create a standard exe project
- Add the following code in form1

Click here to copy the following block
'API Structures
Private Type TIME_OF_DAY_INFO
  tod_elapsed 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

'NetAPI Calls
Private Declare Function NetRemoteTOD Lib "netapi32.dll" ( _
  yServer As Any, pBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32.dll" ( _
  ByVal pBuffer As Long) As Long
  
'Kernel API Calls
Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" ( _
  pTo As Any, uFrom As Any, ByVal lSize As Long)

'Return the Time and Date of a specified Machine on the Net
Public Function GetRemoteTime(servername As String) As Date
  Dim lpBuffer As Long
  Dim t_struct As TIME_OF_DAY_INFO
  Dim ret As Long
  Dim bServer() As Byte

  If Trim(servername) = "" Then
    'Local machine
    ret = NetRemoteTOD(vbNullString, lpBuffer)
  Else
    'Check the syntax of the ServerName string
    If InStr(servername, "\\") = 1 Then
      bServer = servername & vbNullChar
    Else
      bServer = "\\" & servername & vbNullChar
    End If
    ret = NetRemoteTOD(bServer(0), lpBuffer)
  End If
  
  CopyMem t_struct, ByVal lpBuffer, Len(t_struct)
  
  If lpBuffer Then
    Call NetApiBufferFree(lpBuffer)
  End If
  
  GetRemoteTime = DateSerial(t_struct.tod_year, _
                t_struct.tod_month, _
                t_struct.tod_day) _
         + TimeSerial(t_struct.tod_hours, _
                t_struct.tod_mins - t_struct.tod_timezone, _
                t_struct.tod_secs)
End Function

'Get the time and date of the local machine
Private Sub Command1_Click()
  MsgBox GetRemoteTime("")
End Sub

'Get the time and date a remote Workstation
Private Sub Form_Load()
  Dim servername
  servername = InputBox("Please enter name of the server")
  MsgBox "Current time on " & servername & " is : " & _
    GetRemoteTime("\\" & servername)
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.