In C#, how do I query a remote server for its current time?
Similar functionality to
net time \servername
but returning a datestamp that includes seconds.
Thanks
You can use the NetRemoteTOD function.
An example from http://bytes.com/groups/net-c/246234-netremotetod-usage:
// The pointer. IntPtr pintBuffer = IntPtr.Zero; // Get the time of day. int pintError = NetRemoteTOD(@"\sony_laptop", ref pintBuffer); // Get the structure. TIME_OF_DAY_INFO pobjInfo = (TIME_OF_DAY_INFO) Marshal.PtrToStructure(pintBuffer, typeof(TIME_OF_DAY_INFO)); // Free the buffer. NetApiBufferFree(pintBuffer);
2.1m questions
2.1m answers
60 comments
57.0k users