title: How to automatically restart a program after it's closed
body: <p>I'm developing a timer for my kids that will automatically shut down the computer once the time is up and I was trying to figure out a way that the program would automatically restart if it were to be closed via task manager.
  I've posted my code for my program bellow if it's any help.</p>
  
  <pre><code>Imports System
  Imports System.IO
  Imports System.Text
  Imports System.Collections.Generic
  Public Class Digparent
  'add to startupp:
  ' My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
  
  'remove from startup
  'My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName)
  
  'use application setting boolean to not add same application to startup more than once
  'charge for this feature
  
  
  
  'to do
  '
  'wrongn height when make timer unstopable
  'above all
  Dim X, Y As Integer
  Dim NewPoint As New System.Drawing.Point
  Public second As Integer
  Public checkdone As Boolean
  Public checkoff As Boolean
  Public unstop As Boolean
  Dim Mondayt As String
  Dim Tuesdayt As String
  Dim Wendsdayt As String
  Dim Thursdayt As String
  Dim Fridayt As String
  Dim Saturdayt As String
  Dim Sundayt As String
  Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      ' //
      '    //
      '   //
      '  //Start reader
      ' //
      Dim timeinfo As String = "C:\Users\DigiParent\Desktop\Project data\good.txt"
      ' IO.File.SetAttributes("C:\Users\DigiParent\Desktop\Project data\Digitimeinfo.txt", IO.FileAttributes.Hidden)
  
      Dim timeChecker As New System.IO.StreamWriter(timeinfo, True)
      timeChecker.Close()
      Dim readertime As New System.IO.StreamReader(timeinfo, Encoding.Default)
      Dim texttime As String = readertime.ReadToEnd
      readertime.Close()
      If texttime = "" Then
          Dim timeobjWriter As New System.IO.StreamWriter(timeinfo, True)
          timeobjWriter.Write(",,,,")
          timeobjWriter.Close()
      End If
      Dim startup As String = "C:\Users\DigiParent\Desktop\Project data\good.txt"
      Dim reader As New System.IO.StreamReader(startup, Encoding.Default)
      Dim data As String = reader.ReadToEnd
      Dim aryTextFile(6) As String
      aryTextFile = data.Split(",")
      Mondayt = aryTextFile(0)
      Tuesdayt = aryTextFile(1)
      Wendsdayt = aryTextFile(2)
      Thursdayt = aryTextFile(3)
      Fridayt = aryTextFile(4)
      '
      'enable this for saturday and sunday
      '
      'Saturdayt = aryTextFile(5)
      'Sundayt = aryTextFile(6)
      reader.Close()
  
      '    //
      '   //
      '  //Finish reader
      ' //
  
  End Sub
  
  Private Sub Panel2_MouseMove(sender As Object, e As MouseEventArgs) Handles Panel2.MouseMove, time.MouseMove, timeup.MouseMove
      If unstop = True Then
          If e.Button = Windows.Forms.MouseButtons.Left Then
              NewPoint = Control.MousePosition
              NewPoint.X -= (X)
              NewPoint.Y -= (Y)
              Me.Location = NewPoint
          End If
      End If
  End Sub
  
  
  
  Private Sub Panel2_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel2.MouseDown, time.MouseDown, timeup.MouseDown
      If unstop = True Then
          X = Control.MousePosition.X - Me.Location.X
          Y = Control.MousePosition.Y - Me.Location.Y
      End If
  End Sub
  
  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
      NumericUpDownhrs.Left -= 40
      NumericUpDownmin.Left -= 40
      NumericUpDownsec.Left -= 29 '25
      Hourstxt.Left -= 40
      Minutestxt.Left -= 30
      secondstxt.Left -= 30
      Panel1.Left -= 30
      RadioButton2.Left -= 30
      RadioButton1.Left -= 30
      Label4.Left -= 30
      Label5.Left -= 30
      Button4.Left -= 30
      time.Left -= 30
      timeup.Left -= 30
      If RadioButton1.Location = RadioButton5.Location Then
          Timer1.Stop()
  
      Else
      End If
      If Me.Height &lt; 265 Then
          Me.Height = Me.Height + 1
      End If
  
  
  End Sub
  
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      more.Visible = False
      updateb.Visible = False
      feedbackb.Visible = False
      Timer1.Start()
      Button1.Visible = False
  End Sub
  
  Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
  
  End Sub
  
  Private Sub Button4_Click(snder As Object, e As EventArgs) Handles Button4.Click
      My.Settings.Data = True
      If RadioButton6.Checked = True Then
          My.Settings.unstopable = True
          Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
          Me.ShowInTaskbar = False
          Me.ControlBox = False
          Me.Text = ""
          Me.ShowIcon = False
          Me.ShowInTaskbar = False
          Me.ControlBox = False
          unstop = True
          Me.Height = 149
      Else
          My.Settings.unstopable = False
      End If
      If RadioButton1.Checked = True Then
          My.Settings.Shutdown = True
          checkoff = True
          ' System.Diagnostics.Process.Start("ShutDown", "/s")
      Else
          My.Settings.Shutdown = False
      End If
      vhrs = NumericUpDownhrs.Value
      vmin = NumericUpDownmin.Value
      vsec = NumericUpDownsec.Value
      My.Settings.hours = vhrs
      My.Settings.min = vmin
      My.Settings.second = vsec
      PictureBox1.Dock = DockStyle.None
      PictureBox1.Visible = False
      starttime.Start()
      realTimer.Start()
  End Sub
  Public Hrs As Integer  'number of hours   '
  Public Min As Integer  'number of Minutes '
  Public Sec As Integer  'number of Sec     '
  Public Function GetTime(Time As Integer) As String
      'Seconds'
      Sec = Time Mod 60
  
      'Minutes'
      Min = ((Time - Sec) / 60) Mod 60
  
      'Hours'
      Hrs = ((Time - (Sec + (Min * 60))) / 3600) Mod 60
      Return Format(Hrs, "00") &amp; ":" &amp; Format(Min, "00") &amp; ":" &amp; Format(Sec, "00")
  End Function
  Private Sub realTimer_Tick(sender As Object, e As EventArgs) Handles realTimer.Tick
      second = second + 1
      time.Text = GetTime(second)
      'now
      If Min &gt;= vmin And Hrs &gt;= vhrs And Sec &gt;= vsec Then
          checkdone = True
          Me.TopMost = True
          'Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
          endtime.Start()
          If unstop = True Then
              closeb.Visible = True
          End If
          realTimer.Stop()
      End If
      If checkdone = True And checkoff = True Then
  
          endtime.Start()
          System.Diagnostics.Process.Start("ShutDown", "/s")
      End If
  End Sub
  
  Private Sub starttime_Tick(sender As Object, e As EventArgs) Handles starttime.Tick
      time.Left -= 30
      Panel1.Left -= 30
      RadioButton2.Left -= 30
      RadioButton1.Left -= 30
      Label4.Left -= 30
      Label5.Left -= 30
      Button4.Left -= 30
      timeup.Left -= 30
      If time.Location = Label2.Location Then
          starttime.Stop()
      End If
      If Me.Height &gt; 189 Then
          Me.Height = Me.Height - 5
      End If
  End Sub
  
  
  Private Sub endtime_Tick(sender As Object, e As EventArgs) Handles endtime.Tick
      time.Left -= 30
      timeup.Left -= 30
      If timeup.Location = labeltimeup.Location Then
  
          endtime.Stop()
      End If
  End Sub
  
  Private Sub more_Click(sender As Object, e As EventArgs) Handles more.Click
      Form3.Show()
      'more.Visible = False
      'moretimer.Start()
  End Sub
  
  Private Sub moretimer_Tick(sender As Object, e As EventArgs) Handles moretimer.Tick
      If updateb.Location = Updatebutton.Location Then
          moretimer.Stop()
      End If
      feedbackb.Left += 15
      updateb.Left -= 15
  End Sub
  
  Private Sub updateb_Click(sender As Object, e As EventArgs) Handles updateb.Click
      System.Diagnostics.Process.Start("http://digiparent.weebly.com/beta-20-update.html")
  End Sub
  
  Private Sub feedbackb_Click(sender As Object, e As EventArgs) Handles feedbackb.Click
      System.Diagnostics.Process.Start("http://digiparent.weebly.com/feedback.html")
  End Sub
  
  
  Private Sub closeb_Click(sender As Object, e As EventArgs) Handles closeb.Click
      Me.Close()
  End Sub
  
  Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
      NumericUpDownsec.Value = My.Settings.second
      NumericUpDownmin.Value = My.Settings.min
      NumericUpDownhrs.Value = My.Settings.hours
      If My.Settings.Shutdown = True Then
          RadioButton1.Checked = True
      End If
      If My.Settings.unstopable = True Then
          RadioButton6.Checked = True
      End If
      Button2.Visible = False
  End Sub
  
  Private Sub Numericchanged(sender As Object, e As EventArgs) Handles NumericUpDownsec.ValueChanged, NumericUpDownmin.ValueChanged, NumericUpDownhrs.ValueChanged
      If NumericUpDownsec.Value = 0 Then ' NumericUpDownhrs.Value = 0  NumericUpDownmin.Value = 0 Then
  
          If NumericUpDownhrs.Value = 0 Then
              If NumericUpDownmin.Value = 0 Then
  
                  Button2.Visible = True
              Else
                  Button2.Visible = False
              End If
  
          Else
              Button2.Visible = False
          End If
      Else
          Button2.Visible = False
      End If
  
  
  
  
  End Sub
  
  Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click
  
  End Sub
  
  
  
  End Class
  </code></pre>