示例#1
0
 public RegistryTimeZoneInformation(TimeZoneInformation tzi)
 {
     this.Bias         = tzi.Bias;
     this.StandardDate = tzi.StandardDate;
     this.StandardBias = tzi.StandardBias;
     this.DaylightDate = tzi.DaylightDate;
     this.DaylightBias = tzi.DaylightBias;
 }
示例#2
0
        public static void ChangeTimeZone(string standardName)
        {
            var regTimeZones = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones");

            var    subKey       = regTimeZones.GetSubKeyNames().Where(s => s == standardName).First();
            string daylightName = (string)regTimeZones.OpenSubKey(subKey).GetValue("Dlt");

            byte[] tzi = (byte[])regTimeZones.OpenSubKey(subKey).GetValue("TZI");

            var regTzi = new RegistryTimeZoneInformation(tzi);

            TokenPrivilegesAccess.EnablePrivilege("SeTimeZonePrivilege");

            bool didSet;

            if (Environment.OSVersion.Version.Major < 6)
            {
                var tz = new TimeZoneInformation();
                tz.Bias         = regTzi.Bias;
                tz.DaylightBias = regTzi.DaylightBias;
                tz.StandardBias = regTzi.StandardBias;
                tz.DaylightDate = regTzi.DaylightDate;
                tz.StandardDate = regTzi.StandardDate;
                tz.DaylightName = daylightName;
                tz.StandardName = standardName;

                didSet = TimeZoneUtil.SetTimeZoneInformation(ref tz);
            }
            else
            {
                var tz = new DynamicTimeZoneInformation();
                tz.Bias                        = regTzi.Bias;
                tz.DaylightBias                = regTzi.DaylightBias;
                tz.StandardBias                = regTzi.StandardBias;
                tz.DaylightDate                = regTzi.DaylightDate;
                tz.StandardDate                = regTzi.StandardDate;
                tz.DaylightName                = daylightName;
                tz.StandardName                = standardName;
                tz.TimeZoneKeyName             = subKey;
                tz.DynamicDaylightTimeDisabled = false;

                didSet = TimeZoneUtil.SetDynamicTimeZoneInformation(ref tz);
            }
            int lastError = Marshal.GetLastWin32Error();

            TokenPrivilegesAccess.DisablePrivilege("SeTimeZonePrivilege");
        }
示例#3
0
 private static extern bool SetTimeZoneInformation([In] ref TimeZoneInformation lpTimeZoneInformation);