示例#1
0
 private static void SetSystemTimeUtcWindows(DateTime dt)
 {
     Interop.SystemTime st = DateTimeToSystemTime(dt);
     try
     {
         if (!Interop.SetSystemTime(ref st))
         {
             throw new IOException("SetSystemTime returned an unspecified error");
         }
     }
     catch (System.Security.SecurityException x)
     {
         // Let's be exhaustive here, because without google, it's next to impossible to find this setting.
         throw new UnauthorizedAccessException("Permission denied for setting the clock. Either run this program with elevated permissions or make sure " +
                                               "the current user has permission to change the clock. Open 'gpedit.msc' and go to Computer Configuration > Windows Settings > " +
                                               "Security Settings > Local Policies > User Rights Assignments and add the user or his group to the setting " +
                                               "'Change System Time'.", x);
     }
 }
示例#2
0
 private static DateTime SystemTimeToDateTime(ref Interop.SystemTime st)
 {
     return(new DateTime(st.Year, st.Month, st.Day, st.Hour, st.Minute, st.Second, st.Milliseconds));
 }