Znalazłem taki kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ZmienDate
{
class Program
{
[StructLayout(LayoutKind.Sequential)]
private struct SystemTime
{
public ushort Year;
public ushort Month;
public ushort DayOfWeek;
public ushort Day;
public ushort Hour;
public ushort Minute;
public ushort Second;
public ushort Milliseconds;
}
[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
private extern static void Win32GetSystemTime(ref SystemTime lpSystemTime);
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
[return: MarshalAsAttribute(UnmanagedType.Bool)]
private extern static bool Win32SetSystemTime(ref SystemTime lpSystemTime);
static void Main(string[] args)
{
SystemTime updatedTime = new SystemTime();
Win32GetSystemTime(ref updatedTime);
updatedTime.Day = 23;
updatedTime.Month = 4;
updatedTime.Year = 2007;
Win32SetSystemTime(ref updatedTime);
}
}
}
Niestety data w systemie Windows 7 nie zmienia się, dalej jest aktualna. Czy można zmienić datę systemową w jakiś sposób? Czy może data zmieni się dopiero po restarcie komputera czy od razu po wykonaniu programu?