using System.DirectoryServices.ActiveDirectory;
DirectoryContext context = new
DirectoryContext(DirectoryContextType.DirectoryServer, "insert_domain_controller_name_here");
DomainController dc =
DomainController.GetDomainController(context);
DateTime dt = dc.CurrentTime;
MessageBox.Show("Domain Time is " +
dt.ToLongTimeString());
Friday, June 11, 2010
C# example of directly getting the local time from a Domain Controller
In case you need to get the current time (appears to be UTC) from a trusted source rather than rely on the local computer to report the time (which can be easily changed), this snippet gives guidance. You can get the name of a domain controller from the LOGONSERVER environment variable.
Subscribe to:
Posts (Atom)