0

I want run a process on at a specific time (4:00 AM). Here is my code:

if(Current time == 4:00)
{
    ProcessStartInfo autorestart = new ProcessStartInfo(@"C:\Autostart.bat");
    autorestart.UseShellExecute = false;
    SecureString pw = new SecureString();

    pw.AppendChar('p');
    pw.AppendChar('a');
    pw.AppendChar('s');
    pw.AppendChar('s');
    pw.AppendChar('w');
    pw.AppendChar('o');
    pw.AppendChar('r');
    pw.AppendChar('d');

    autorestart.Password = pw;
    autorestart.UserName = "support";
    Process.Start(autorestart);
}
else
{
    MessageBox.Show("Time not same");
}
AGB
  • 2,230
  • 1
  • 14
  • 21
abid
  • 25
  • 5
  • Please clarify: does your method run only once? Or is it looping and waiting until *after* it's 4:00 AM? Then does it exit after the first time it runs the body of the code (i.e. after 4:00 AM) or does it keep running until tomorrow's 4:00 AM and on and on? The answers to these questions may or may not require that you store state somewhere so it doesn't execute more than once per day. – rory.ap Apr 16 '16 at 15:46
  • How about `DateTime.Now.ToString("H:mm").Equals("4:00")` ? – Hari Prasad Apr 16 '16 at 15:46
  • It should be "H:mm". @HariPrasad – Hamid Pourjam Apr 16 '16 at 15:46
  • @dotctor true, ahh.. missed it. :-) – Hari Prasad Apr 16 '16 at 15:47
  • yes doctor i want to perform the restart every day on 4 o clock in the morning – abid Apr 16 '16 at 15:56
  • great Doctor.realy so nice of you it worked.doctor one more question may i asked that my system task.schedule service is getting automaticaly down and i have to start it again through none admin acount.so will you give me any idea for that in c# code pleaseeeeeeeeee – abid Apr 16 '16 at 16:03

0 Answers0