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.
Printable View
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.
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
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.