using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace ChangeDate
{
public partial class Form1 : Form
{
DateTime now = DateTime.Now;
public int rokUzytkownika;
public 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 Millisecond;
};
[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);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
label1.Text = null;
try
{
SystemTime updatedTime = new SystemTime();
updatedTime.Year = (ushort)2007;
updatedTime.Month = (ushort)now.Month;
updatedTime.Day = (ushort)now.Day;
updatedTime.Day = (ushort)now.Hour;
updatedTime.Day = (ushort)now.Minute;
updatedTime.Day = (ushort)now.Second;
updatedTime.Day = (ushort)now.Millisecond;
Win32SetSystemTime(ref updatedTime);
label1.Text = "Gotowe";
}
catch (Exception ex)
{
MessageBox.Show("Nie udało się zmienić daty. Proszę sprawdzić czy program został włączony z prawami administratora. " + ex, "Komunikat");
}
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;//odblkowujemy klawisz jeśli jest to 0,1,2,3,4,5,6,7,9
if (e.KeyChar == '0' ||
e.KeyChar == '1' ||
e.KeyChar == '2' ||
e.KeyChar == '3' ||
e.KeyChar == '4' ||
e.KeyChar == '5' ||
e.KeyChar == '6' ||
e.KeyChar == '7' ||
e.KeyChar == '8' ||
e.KeyChar == '9')
{
e.Handled = false;
}
if (Convert.ToInt32(e.KeyChar) == 8)//odblokowujemy backspace
{
e.Handled = false;
}
}
private void buttonUstaw_Click(object sender, EventArgs e)
{
label1.Text = null;
try
{
rokUzytkownika = int.Parse(textBox1.Text);
SystemTime updatedTime = new SystemTime();
updatedTime.Year = (ushort)rokUzytkownika;
updatedTime.Month = (ushort)now.Month;
updatedTime.Day = (ushort)now.Day;
updatedTime.Day = (ushort)now.Hour;
updatedTime.Day = (ushort)now.Minute;
updatedTime.Day = (ushort)now.Second;
updatedTime.Day = (ushort)now.Millisecond;
Win32SetSystemTime(ref updatedTime);
label1.Text = "Gotowe";
}
catch (Exception ex)
{
MessageBox.Show("Nie udało się zmienić daty. Proszę sprawdzić czy program został włączony z prawami administratora. " + ex, "Komunikat");
}
}
}
}
Już nie wiem co tu jest źle. Teraz wcale nie zmienia nawet roku, a nie wiem dlaczego, skoro wcześniej rok się zmieniał, tylko był problem, że godzina się zmieniała. Po prostu chce zmieniać sam rok, pozostawiając godzinę i datę.