悉野小楼

导航

C#修改电脑时间

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace settime
{
    class Program
    {
        public struct SystemTime
        {
            public short wYear;
            public short wMonth;
            public short wDayOfWeek;
            public short wDay;
            public short wHour;
            public short wMinute;
            public short wSecond;
            public short wMilliseconds;
        }

        [DllImport("kernel32.dll", SetLastError = true)]
        public static extern int SetLocalTime(ref SystemTime lpSystemTime);

        static void Main(string[] args)
        {
            DateTime newDate = DateTime.Now.AddDays(1);
            SystemTime sysNew = new SystemTime();
            sysNew.wDay = (short)newDate.Day;
            sysNew.wMonth = (short)newDate.Month;
            sysNew.wYear = (short)newDate.Year;
            sysNew.wHour = 8;
            sysNew.wMinute = 59;
            sysNew.wSecond = 55;
            SetLocalTime(ref sysNew);
        }
    }
}

posted on 2012-10-22 15:36  悉野  阅读(868)  评论(0编辑  收藏  举报