hi,

i would like to check the server datetime when ever my application start. The datetime must be the same with my pc datetime....How do i do that...Is there a way....
i got a code from somewhere but it doesn't work at all...can anyone help me on this....

Public Sub GetServerDateTime()
        Dim WMIScope As Management.ManagementScope
        Dim WMIConnectionOptions As New Management.ConnectionOptions
        Dim oq As New System.Management.ObjectQuery
        Dim query As ManagementObjectSearcher
        Dim queryCollection As ManagementObjectCollection
        Dim Strcomputer As String = "111.222.333.58"

        With WMIConnectionOptions
            .Impersonation = System.Management.ImpersonationLevel.Impersonate
            .Authentication = System.Management.AuthenticationLevel.Packet
        End With

        WMIScope = New Management.ManagementScope("\\" & _
                    Strcomputer & "\root\cimv2", WMIConnectionOptions)

        oq = New System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem")
        query = New ManagementObjectSearcher(WMIScope, oq)
        queryCollection = query.Get()

        For Each oReturn As ManagementObject In queryCollection
            Debug.Print(oReturn("LocalDateTime").ToString())
        Next

      
    End Sub

hi,

below is my code to get server date time. I create this using webservices.asmx . Once run i upload the web reference to my server using IIS as ServerTime.

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel


<System.Web.Services.WebService(Namespace:="http://123.111.11.66")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class ServerTime
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function ServerDateTime() As String
        Dim dateTimeStr As String
        Dim tZn As TimeZone             'get the time zone 
        Dim tZnNameStr As String        'time zone name (CST, EST, etc) 
        tZn = System.TimeZone.CurrentTimeZone 'get name of time zone
        If tZn.IsDaylightSavingTime(Now) Then
            tZnNameStr = tZn.DaylightName
        Else
            tZnNameStr = tZn.StandardName
        End If
               dateTimeStr = Format(Now, "MM/dd/yyyy hh:mm:ss tt")
        Return dateTimeStr
    End Function
End Class

below is the way i call from my application to compare the server datetime and my pc datetime....But i'm not getting the response from the server site.....when i run my application it's just compare with my pc time......

If GetServerDateTime() < Format(Now, "MM/dd/yyyy hh:mm:ss tt") Then
              MsgBox("You datetime not valid")
                Application.Exit()
                         End If

Please help....i think i have directed to wrong webservice.....how do i make to correct webservice.....any idea ????

Edited 5 Years Ago by swathys: n/a

This article has been dead for over six months. Start a new discussion instead.