Пример #1
0
        internal static void SetSystemDate(ushort month, ushort day, ushort year)
        {
            var systemDate = new SystemDateTime();
            GetSystemTime(ref systemDate);

            systemDate.Month = month;
            systemDate.Day = day;
            systemDate.Year = year;

            if (!SetSystemTime(ref systemDate))
            {
                var exceptionCode = Marshal.GetLastWin32Error();
                if (exceptionCode == 1314)
                {
                    throw new ApplicationException("You must run Visual Studio as an Administrator to modify the system's date/time.");
                }
                throw new ApplicationException(string.Format("The system threw a Windows Exception with code {0}", exceptionCode));
            }
        }
Пример #2
0
 private static extern bool SetSystemTime(ref SystemDateTime lpSystemTime);
Пример #3
0
 private static extern void GetSystemTime(ref SystemDateTime lpSystemTime);