DayLight information is completeely diffrent in each year in my computer, so in order i have a correct daylight Time in each year , i have created a database of daylight timing for each year and it exists in
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Iran Standard Time\Dynamic DST.
So my application does as following:
1- Get the proper record for next year (in a specified date)
2- set the record in the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Iran Standard Time\
TZI value
3- set the related part of the record in the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation (StandardStart and DaylightStart Section)
4- then i restart the Time service
actually i think there isn nothing left which i should do, but it doesn't work all the time.
can any one help what else should i consider , where is wrong?
/*************** Section 1************/
ThisYear = GetIniFileString(iniFile, "ChagingYear", System.DateTime.Now.Year.ToString(), defaultValue);
string[] words = null;
int[] wordsint = new int[bytes.Length];
words = ThisYear.Split(new Char[] { ',' });
int maxbyte = bytes.Length;
for (int i = 0; i < maxbyte; i++)
{
wordsint = Convert.ToInt32(words, 16);
bytes = Convert.ToByte(wordsint);
}
/****** Section 2 *****/
OurKey.SetValue("TZI", bytes);
OurKey.Flush();
OurKey.Close();
/**************section 3***************/
str = "System\\CurrentControlSet\\Control\\TimeZoneInformation";
OurKey1 = OurKey1.OpenSubKey(@str, true);
byte[] bytesAct=new byte[16];
for (int i=12; i<28 ;i++)
bytesAct[i-12]=bytes;
OurKey1.SetValue("StandardStart", bytesAct);
for (int i = 28; i < 44; i++)
bytesAct[i - 28] = bytes;
OurKey1.SetValue("DaylightStart", bytesAct);
OurKey1.Flush();
OurKey1.Close();
/********* Section 4********/
ServiceController controller = new ServiceController();
controller.MachineName = System.Environment.MachineName;
controller.ServiceName = "W32Time";
// Stop the service
controller.Stop();
// Start the service
if (controller.Status.ToString()=="Stopped")
controller.Start();
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Iran Standard Time\Dynamic DST.
So my application does as following:
1- Get the proper record for next year (in a specified date)
2- set the record in the
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Iran Standard Time\
TZI value
3- set the related part of the record in the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation (StandardStart and DaylightStart Section)
4- then i restart the Time service
actually i think there isn nothing left which i should do, but it doesn't work all the time.
can any one help what else should i consider , where is wrong?
/*************** Section 1************/
ThisYear = GetIniFileString(iniFile, "ChagingYear", System.DateTime.Now.Year.ToString(), defaultValue);
string[] words = null;
int[] wordsint = new int[bytes.Length];
words = ThisYear.Split(new Char[] { ',' });
int maxbyte = bytes.Length;
for (int i = 0; i < maxbyte; i++)
{
wordsint = Convert.ToInt32(words, 16);
bytes = Convert.ToByte(wordsint);
}
/****** Section 2 *****/
OurKey.SetValue("TZI", bytes);
OurKey.Flush();
OurKey.Close();
/**************section 3***************/
str = "System\\CurrentControlSet\\Control\\TimeZoneInformation";
OurKey1 = OurKey1.OpenSubKey(@str, true);
byte[] bytesAct=new byte[16];
for (int i=12; i<28 ;i++)
bytesAct[i-12]=bytes;
OurKey1.SetValue("StandardStart", bytesAct);
for (int i = 28; i < 44; i++)
bytesAct[i - 28] = bytes;
OurKey1.SetValue("DaylightStart", bytesAct);
OurKey1.Flush();
OurKey1.Close();
/********* Section 4********/
ServiceController controller = new ServiceController();
controller.MachineName = System.Environment.MachineName;
controller.ServiceName = "W32Time";
// Stop the service
controller.Stop();
// Start the service
if (controller.Status.ToString()=="Stopped")
controller.Start();