How can i access Time from Server ?

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2005
Posts: 6
Reputation: abhay_fgr is an unknown quantity at this point 
Solved Threads: 0
abhay_fgr abhay_fgr is offline Offline
Newbie Poster

How can i access Time from Server ?

 
0
  #1
Aug 23rd, 2005
how can i access Time from Server, i am using ADODB in VB6.0 and
Sql Server 8.0.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 514
Reputation: techniner is an unknown quantity at this point 
Solved Threads: 19
techniner techniner is offline Offline
Posting Pro

Re: How can i access Time from Server ?

 
0
  #2
Aug 23rd, 2005
API DECLARTIONS
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. 'API Structures
  4. Type TIME_OF_DAY_INFO
  5. tod_elapsed As Long
  6. tod_msecs As Long
  7. tod_hours As Long
  8. tod_mins As Long
  9. tod_secs As Long
  10. tod_hunds As Long
  11. tod_timezone As Long
  12. tod_tinterval As Long
  13. tod_day As Long
  14. tod_month As Long
  15. tod_year As Long
  16. tod_weekday As Long
  17. End Type
  18.  
  19. 'NetAPI Calls
  20. Public Declare Function NetRemoteTOD Lib "netapi32.dll" (yServer As Any, pBuffer As Long) As Long
  21. Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal pBuffer As Long) As Long
  22. 'Kernel API Calls
  23. Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)

MODULE
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'Return the Time and Date of a specified Machine on the Net
  2. Public Function GetRemoteTime(ServerName As String) As Date
  3. Dim lpBuffer As Long
  4. Dim t_struct As TIME_OF_DAY_INFO
  5. Dim ret As Long
  6. Dim bServer() As Byte
  7.  
  8. If Trim(ServerName) = "" Then
  9. 'Local machine
  10. ret = NetRemoteTOD(vbNullString, lpBuffer)
  11. Else
  12. 'Check the syntax of the ServerName string
  13. If InStr(ServerName, "\\") = 1 Then
  14. bServer = ServerName & vbNullChar
  15. Else
  16. bServer = "\\" & ServerName & vbNullChar
  17. End If
  18. ret = NetRemoteTOD(bServer(0), lpBuffer)
  19. End If
  20. CopyMem t_struct, ByVal lpBuffer, Len(t_struct)
  21. If lpBuffer Then
  22. Call NetApiBufferFree(lpBuffer)
  23. End If
  24. 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)
  25. End Function

Usage

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'Get the time and date of the local machine
  2. Private Sub Command1_Click()
  3. MsgBox GetRemoteTime("")
  4. End Sub
  5.  
  6. 'Get the time and date a remote Workstation
  7. Private Sub Command2_Click()
  8. MsgBox GetRemoteTime("\\MYWORKSTATION")
  9. End Sub
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 4
Reputation: shashikanth is an unknown quantity at this point 
Solved Threads: 0
shashikanth shashikanth is offline Offline
Newbie Poster

Re: How can i access Time from Server ?

 
0
  #3
Oct 22nd, 2005
Originally Posted by techniner
API DECLARTIONS
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. 'API Structures
  4. Type TIME_OF_DAY_INFO
  5. tod_elapsed As Long
  6. tod_msecs As Long
  7. tod_hours As Long
  8. tod_mins As Long
  9. tod_secs As Long
  10. tod_hunds As Long
  11. tod_timezone As Long
  12. tod_tinterval As Long
  13. tod_day As Long
  14. tod_month As Long
  15. tod_year As Long
  16. tod_weekday As Long
  17. End Type
  18.  
  19. 'NetAPI Calls
  20. Public Declare Function NetRemoteTOD Lib "netapi32.dll" (yServer As Any, pBuffer As Long) As Long
  21. Private Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal pBuffer As Long) As Long
  22. 'Kernel API Calls
  23. Private Declare Sub CopyMem Lib "kernel32.dll" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)

MODULE
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'Return the Time and Date of a specified Machine on the Net
  2. Public Function GetRemoteTime(ServerName As String) As Date
  3. Dim lpBuffer As Long
  4. Dim t_struct As TIME_OF_DAY_INFO
  5. Dim ret As Long
  6. Dim bServer() As Byte
  7.  
  8. If Trim(ServerName) = "" Then
  9. 'Local machine
  10. ret = NetRemoteTOD(vbNullString, lpBuffer)
  11. Else
  12. 'Check the syntax of the ServerName string
  13. If InStr(ServerName, "\\") = 1 Then
  14. bServer = ServerName & vbNullChar
  15. Else
  16. bServer = "\\" & ServerName & vbNullChar
  17. End If
  18. ret = NetRemoteTOD(bServer(0), lpBuffer)
  19. End If
  20. CopyMem t_struct, ByVal lpBuffer, Len(t_struct)
  21. If lpBuffer Then
  22. Call NetApiBufferFree(lpBuffer)
  23. End If
  24. 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)
  25. End Function

Usage

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 'Get the time and date of the local machine
  2. Private Sub Command1_Click()
  3. MsgBox GetRemoteTime("")
  4. End Sub
  5.  
  6. 'Get the time and date a remote Workstation
  7. Private Sub Command2_Click()
  8. MsgBox GetRemoteTime("\\MYWORKSTATION")
  9. End Sub

This code is running in NT, XP machine. but when exe in executed from win98 then database in updating the field with 01-01-1900. Please help me how to get time from server when we r working in win98
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC