Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can i please ask how to get the time in each server in my network
example : I wont to run application on my computer to know what the exact time in each server in my network

Thanks in advance
Posted
Comments
Sandeep Mewara 11-Sep-12 3:48am    
Tagged as C#, and talking of servers!

You asking question for web application?
Volynsky Alex 11-Sep-12 5:50am    
Maybe it will help you :
http://stackoverflow.com/questions/1602036/how-to-list-all-computers-and-the-last-time-they-were-logged-onto-in-ad

 
Share this answer
 
You may use this code:
C#
System.Net.Sockets.TcpClient t = new System.Net.Sockets.TcpClient("panic", 13);
System.IO.StreamReader rd = new System.IO.StreamReader(t.GetStream());
MessageBox.Show(rd.ReadToEnd());

but it requires that port 13 on the server is accessible for you.
Or you may try the command line command "net time \\servername" using this code:
C#
System.Diagnostics.ProcessStartInfo psiOpt = new System.Diagnostics.ProcessStartInfo(@"cmd.exe", @"/C net time \\servername");
psiOpt.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
psiOpt.RedirectStandardOutput = true;
psiOpt.UseShellExecute = false;
psiOpt.CreateNoWindow = true;
System.Diagnostics.Process procCommand = System.Diagnostics.Process.Start(psiOpt);
StreamReader srIncoming = procCommand.StandardOutput;
MessageBox.Show(srIncoming.ReadToEnd());
procCommand.WaitForExit();

You then only need to parse the command response for the DateTime.
 
Share this answer
 
Comments
eman88 11-Sep-12 6:55am    
Thank U for ur help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900