Witam, chciałbym zmieniać datę systemową pod jakimiś tam warunkami.
na razie dla testów z pomocą wyszukiwarki ma taki kod. Dziwnie mi działa, bo
- zawsze zmienia date na 23 kwiecień 2008 pomimo tego co ma w kodzie
- kod dokładnie w takiej postaci jak wkleiłem ( czyli sporo pokomentowane ) tak i tak zwraca mi np. msgBoxa. Dlaczego?
godziny nie chcę w ogóle ruszać. Co robię nie tak?
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
public extern static void Win32GetSystemTime(ref SystemTime sysTime);
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SystemTime sysTime);
private void timer1_Tick(object sender, EventArgs e)
{
//DateTime dtToday = DateTime.Now;
// run this code under some condition to set system date and time
SystemTime updatedTime = new SystemTime();
updatedTime.Year = (ushort)2011;
updatedTime.Month = (ushort)4;
updatedTime.Day = (ushort)23;
// UTC time; it will be modified according to the regional settings of the target computer so the
// actual hour might differ
//updatedTime.Hour = (ushort)10;
//updatedTime.Minute = (ushort)0;
//updatedTime.Second = (ushort)0;
// Call the unmanaged function that sets the new date and time instantly
Win32SetSystemTime(ref updatedTime);
// Retrieve the current system date and time
//SystemTime currTime = new SystemTime();
//Win32GetSystemTime(ref currTime);
// You can now use the struct to retrieve the date and time
//MessageBox.Show("It's " + currTime.Hour + " o'clock. Do you know where your C# code is?");
}