How do I set the date/time of the computer in C#?
A:
You will need to call the SetSystemTime Win32 API function through P/Invoke.
Greg Hewgill
2008-11-10 19:51:57
+3
A:
You'll have to use a P/Invoke to the Windows API.
Here's some example code in C#
Luke
2008-11-10 19:51:58
+3
A:
You can set the date using Microsoft.VisualBasic.Today and Microsoft.VisualBasic.TimeOfDay, although they're subject to security restrictions.
Yes, it's strange accessing the Microsoft,VisualBasic namespace, but there doesn't appear to be a C# equivalent.
R. Bemrose
2008-11-10 20:06:40
It's just a .NET framework namespace. C# is not going to get infected by VB-ism just by using classes from Microsoft.VisualBasic. The J# libraries have several goodies too.
Hans Passant
2008-11-10 21:05:01