944,149 Members | Top Members by Rank

Ad:
Aug 23rd, 2005
0

How can i access Time from Server ?

Expand Post »
how can i access Time from Server, i am using ADODB in VB6.0 and
Sql Server 8.0.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
abhay_fgr is offline Offline
6 posts
since Jul 2005
Aug 23rd, 2005
0

Re: How can i access Time from Server ?

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
Reputation Points: 12
Solved Threads: 19
Posting Pro
techniner is offline Offline
521 posts
since May 2005
Oct 22nd, 2005
0

Re: How can i access Time from Server ?

Quote 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
shashikanth is offline Offline
4 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: vb6 error help me
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: pictureBox problem.. please help me!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC