vb.net - How to automatically restart a program after it's closed -
i'm developing timer kids automatically shut down computer once time , trying figure out way program automatically restart if closed via task manager. i've posted code program bellow if it's help.
imports system imports system.io imports system.text imports system.collections.generic public class digparent 'add startupp: ' my.computer.registry.localmachine.opensubkey("software\microsoft\windows\currentversion\run", true).setvalue(application.productname, application.executablepath) 'remove startup 'my.computer.registry.localmachine.opensubkey("software\microsoft\windows\currentversion\run", true).deletevalue(application.productname) 'use application setting boolean not add same application startup more once 'charge feature 'to ' 'wrongn height when make timer unstopable 'above dim x, y integer dim newpoint new system.drawing.point public second integer public checkdone boolean public checkoff boolean public unstop boolean dim mondayt string dim tuesdayt string dim wendsdayt string dim thursdayt string dim fridayt string dim saturdayt string dim sundayt string private sub form2_load(sender object, e eventargs) handles mybase.load ' // ' // ' // ' //start reader ' // dim timeinfo 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 new system.io.streamwriter(timeinfo, true) timechecker.close() dim readertime new system.io.streamreader(timeinfo, encoding.default) dim texttime string = readertime.readtoend readertime.close() if texttime = "" dim timeobjwriter new system.io.streamwriter(timeinfo, true) timeobjwriter.write(",,,,") timeobjwriter.close() end if dim startup string = "c:\users\digiparent\desktop\project data\good.txt" dim reader new system.io.streamreader(startup, encoding.default) dim data string = reader.readtoend dim arytextfile(6) string arytextfile = data.split(",") mondayt = arytextfile(0) tuesdayt = arytextfile(1) wendsdayt = arytextfile(2) thursdayt = arytextfile(3) fridayt = arytextfile(4) ' 'enable saturday , sunday ' 'saturdayt = arytextfile(5) 'sundayt = arytextfile(6) reader.close() ' // ' // ' //finish reader ' // end sub private sub panel2_mousemove(sender object, e mouseeventargs) handles panel2.mousemove, time.mousemove, timeup.mousemove if unstop = true if e.button = windows.forms.mousebuttons.left newpoint = control.mouseposition newpoint.x -= (x) newpoint.y -= (y) me.location = newpoint end if end if end sub private sub panel2_mousedown(sender object, e mouseeventargs) handles panel2.mousedown, time.mousedown, timeup.mousedown if unstop = true x = control.mouseposition.x - me.location.x y = control.mouseposition.y - me.location.y end if end sub private sub timer1_tick(sender object, e 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 timer1.stop() else end if if me.height < 265 me.height = me.height + 1 end if end sub private sub button1_click(sender object, e 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 object, e eventargs) handles radiobutton5.checkedchanged end sub private sub button4_click(snder object, e eventargs) handles button4.click my.settings.data = true if radiobutton6.checked = true 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 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 integer 'number of hours ' public min integer 'number of minutes ' public sec integer 'number of sec ' public function gettime(time integer) 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") & ":" & format(min, "00") & ":" & format(sec, "00") end function private sub realtimer_tick(sender object, e eventargs) handles realtimer.tick second = second + 1 time.text = gettime(second) 'now if min >= vmin , hrs >= vhrs , sec >= vsec checkdone = true me.topmost = true 'me.formborderstyle = windows.forms.formborderstyle.fixedsingle endtime.start() if unstop = true closeb.visible = true end if realtimer.stop() end if if checkdone = true , checkoff = true endtime.start() system.diagnostics.process.start("shutdown", "/s") end if end sub private sub starttime_tick(sender object, e 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 starttime.stop() end if if me.height > 189 me.height = me.height - 5 end if end sub private sub endtime_tick(sender object, e eventargs) handles endtime.tick time.left -= 30 timeup.left -= 30 if timeup.location = labeltimeup.location endtime.stop() end if end sub private sub more_click(sender object, e eventargs) handles more.click form3.show() 'more.visible = false 'moretimer.start() end sub private sub moretimer_tick(sender object, e eventargs) handles moretimer.tick if updateb.location = updatebutton.location moretimer.stop() end if feedbackb.left += 15 updateb.left -= 15 end sub private sub updateb_click(sender object, e eventargs) handles updateb.click system.diagnostics.process.start("http://digiparent.weebly.com/beta-20-update.html") end sub private sub feedbackb_click(sender object, e eventargs) handles feedbackb.click system.diagnostics.process.start("http://digiparent.weebly.com/feedback.html") end sub private sub closeb_click(sender object, e eventargs) handles closeb.click me.close() end sub private sub button2_click(sender object, e eventargs) handles button2.click numericupdownsec.value = my.settings.second numericupdownmin.value = my.settings.min numericupdownhrs.value = my.settings.hours if my.settings.shutdown = true radiobutton1.checked = true end if if my.settings.unstopable = true radiobutton6.checked = true end if button2.visible = false end sub private sub numericchanged(sender object, e eventargs) handles numericupdownsec.valuechanged, numericupdownmin.valuechanged, numericupdownhrs.valuechanged if numericupdownsec.value = 0 ' numericupdownhrs.value = 0 numericupdownmin.value = 0 if numericupdownhrs.value = 0 if numericupdownmin.value = 0 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 object, e eventargs) handles label4.click end sub end class
here's basic windowless watchdog app.
start standard winforms project. add module. add public sub main it. go project --> properties --> application tab, , uncheck "enable application framework" box. above that, change "startup object:" dropdown "form1" "sub main".
the code...
module module1 public sub main() application.run(new watchdog) end sub end module public class watchdog inherits applicationcontext private apptowatch string private fullpath string = "c:\windows\system32\calc.exe" private withevents p process public sub new() apptowatch = system.io.path.getfilenamewithoutextension(fullpath) dim ps() process = process.getprocessesbyname(apptowatch) if ps.length = 0 startit() else p = ps(0) p.enableraisingevents = true end if end sub private sub p_exited(sender object, e eventargs) handles p.exited startit() end sub private sub startit() p = process.start(fullpath) p.enableraisingevents = true end sub end class
Comments
Post a Comment