CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2000
    Posts
    29

    Server date and time

    Hi! I just wanted to ask if there is a way to access the server date and time when you are in a client computer. Are there any existing function that I could use in order to do this? Thanks. Hope you can help me.


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: Server date and time

    You could use the "NET TIME" DOS command by wrapping it in a batch file and using it through VB, i.e.option Explicit

    private Sub Command1_Click()
    Dim iFile as Integer
    Dim sResults as string

    iFile = FreeFile
    Open "C:\~Temp.bat" for Output as iFile
    print #iFile, "NET time " & txtServerName & " > C:\~Results.txt";
    Close iFile

    If len(Dir("C:\~Results.txt")) then Kill "C:\~Results.txt"
    Caption = "Checking server """ & txtServerName & """..."
    Shell "C:\~Temp.bat", vbHide

    While len(Dir("C:\~Results.txt")) = 0
    DoEvents
    Wend
    While FileLen("C:\~Results.txt") = 0
    DoEvents
    Wend

    iFile = FreeFile
    Open "C:\~Results.txt" for input as iFile
    sResults = input(LOF(iFile), iFile)
    Close iFile

    If InStr(LCase(sResults), "incorrect") Or InStr(LCase(sResults), "error ") then
    Caption = "UnKnown."
    else
    sResults = mid(sResults, InStr(sResults, " is ") + 4)
    sResults = Left(sResults, InStr(sResults, vbCrLf) - 1)
    Caption = sResults
    End If
    End Sub



    Aaron Young
    Senior Programmer Analyst
    [email protected]
    Certified AllExperts Expert: http://www.allexperts.com/displayExp...p?Expert=11884
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Server date and time

    It is great to read from you again!
    Best regards,
    Cesare Imperiali

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured