Click here to Skip to main content
15,889,831 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I cant change the systemdate, any ideas?
C#
public struct Data
   {
     public ushort Year;
     public ushort Day;
     public ushort Month;
     public ushort Hour;
     public ushort Minute;
     public ushort Second;
     public ushort Millisecond;
     public ushort DayOfWeek;

   }
   class smth
        {
            [DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
            public extern static void Win32GetSystemTime(ref Data sysTime);
       [DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
       public extern static bool wSetSystemTime(ref Data sysTime);
   }

       public Form1()
       {
           InitializeComponent();
       }

       private void Form1_Load(object sender, EventArgs e)
       {

       }

       private void button1_Click(object sender, EventArgs e)
       {
           Data modifica = new Data();
           smth n = new smth();
           modifica.Day = (ushort) (ushort)dateTimePicker1.Value.Day;
           modifica.luna=(ushort) dateTimePicker1.Value.Month;
           modifica.an = (ushort)dateTimePicker1.Value.Year;
           MessageBox.Show(dateTimePicker1.Value.ToString());
          if( smth.wSetSystemTime(ref modifica))
              throw new System.ComponentModel.Win32Exception();
       }
Posted

1 solution

 
Share this answer
 
Comments
SGS97 9-Mar-15 10:48am    
How am I supossed to insert that in my code.
Sorry really new to c#.
Richard MacCutchan 9-Mar-15 11:03am    
You will have to follow the link and read the section on setting privileges. However, you will not be able to do it unless you are running under an administrative account. Basically what it is saying is that you cannot do it, and for very good reasons.

If you are new to C# then you should concentrate on some more practical C# tutorials, such as those at http://msdn.microsoft.com/en-us/library/aa288436(VS.71).aspx.
SGS97 9-Mar-15 11:12am    
Tnx for the link i will use it.
I want to run this program on windows xp,but im testing it on windows 8;
Tnx again for help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900