How to sync client computer time with a server computer time using C#

How to sync client computer time with a server computer time using C#?
(besides using "use net time \\servername /set /y").
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

In general this is a very bad thing to do.  Clients using C# will be running on a Windows platform and should have a local, correct time.  This is required for domains to function correctly and the Windows Time Service provides this function.  See

Also, you normally need local administrator rights to change the system time.

Nevertheless, if you have the security privileges you can do this using WMI.

See the following for WMI and scripting references:

To do this in C#, you need to use the System.Management namespace which exposes WMI functionality.  You will need to use the Invoke method to run the SetDateTime method of the Win32_OperatingSystem object.

See for an intro to WMI in .NET.  and for an example.

You might find that an easier option is to use Platform Invoke with the SetSystemTime Win32 function which is referenced here:

Here's an old example for Visual Basic (not .NET):

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sepknowAuthor Commented:
Quite a bit to digest.
Let me go through and come back to you later.
You're welcome.  If you get stuck, feel free to ask.  I'll be away from my desk later, but there are other experts too...
Thanks for the points :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.