المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Why Don't Change Server Time? (Please Help, It is very urgent)



C# Programming
10-01-2009, 03:02 AM
I wrote a Web application by ASP.NET and C#. I need to change date of my server behind about 1 year ago and after that changing date came back. For example, time is 30/09/2009 and when the program runs, time should be 30/09/2008 and after 3sec time comes back 30/09/2009.
I wrote this rule by ASP.NET and C# and that web application work correctly, but for 5 days, that code can't change date of server, although web application worked correctly and could change date by below codes.
Also these codes work and can change date of server when those are written as WIN application and don't return any error, and those are written as WEB application and run in Visual Studio 2008 don't return any error and works correctly, but when those codes are written as WEB application and run in ISS can't change date of server and return "error: 1314", so I be confused!!!
I will be very glad if somebody helps me.
Thank you very much.


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

[DllImport("kernel32.dll", SetLastError = true)]
private static extern uint GetLastError();

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;
}

private void ChangeDate()
{
SystemTime systNew = new SystemTime();
systNew.wDay = (short)dateTime.Day;
systNew.wMonth = (short)dateTime.Month;
systNew.wYear = (short)2008;
systNew.wHour = (short)dateTime.Hour;
systNew.wMinute = (short)dateTime.Minute;
systNew.wSecond = (short)dateTime.Second;
SetLocalTime(ref systNew);
uint lastErrCode = GetLastError();

}