Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

daylight changing automatically each year

Status
Not open for further replies.

tek1ket

MIS
Jan 25, 2009
70
IR
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();
 
Is it just the last bit that doesn't work - do you need a while loop to wait for the service to stop or does it only come back when it has stopped?
 
yes i have done it by
System.Threading.Thread.Sleep(10000);

but there is no difference
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top