Vb.net 如何在程序启动后自动重新启动';关门了
我正在为我的孩子们开发一个计时器,一旦时间到了,它会自动关闭计算机。我试图找到一种方法,如果通过任务管理器关闭程序,它会自动重新启动。 如果有什么帮助的话,我已经在下面发布了我的程序代码Vb.net 如何在程序启动后自动重新启动';关门了,vb.net,Vb.net,我正在为我的孩子们开发一个计时器,一旦时间到了,它会自动关闭计算机。我试图找到一种方法,如果通过任务管理器关闭程序,它会自动重新启动。 如果有什么帮助的话,我已经在下面发布了我的程序代码 Imports System Imports System.IO Imports System.Text Imports System.Collections.Generic Public Class Digparent 'add to startupp: ' My.Computer.Registry.Loca
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 < 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") & ":" & Format(Min, "00") & ":" & 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 >= vmin And Hrs >= vhrs And Sec >= 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 > 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
导入系统
导入System.IO
导入系统文本
导入System.Collections.Generic
公共类Digparent
'添加到startupp:
'My.Computer.Registry.LocalMachine.OpenSubKey(“SOFTWARE\Microsoft\Windows\CurrentVersion\Run”,True).SetValue(Application.ProductName,Application.ExecutablePath)
'从启动中删除
'My.Computer.Registry.LocalMachine.OpenSubKey(“SOFTWARE\Microsoft\Windows\CurrentVersion\Run”,True)。DeleteValue(Application.ProductName)
'使用应用程序设置布尔值,不能将同一应用程序多次添加到启动中
'此功能的费用
”“怎么办
'
“使计时器不可着色时的错误高度
“最重要的是
将X、Y调整为整数
将新点标注为新系统.Drawing.Point
公共秒作为整数
公共checkdone作为布尔值
作为布尔值的公共checkoff
作为布尔函数的公共unstop
昏暗的星期一
昏暗的星期二
作为字符串的Dim Wendsdayt
昏暗的星期四
昏暗的星期五
昏暗的周六
朦胧的圣代如弦
私有子表单2_Load(发送方作为对象,e作为事件参数)处理MyBase.Load
' //
' //
' //
“//启动读卡器
' //
Dim timeinfo As String=“C:\Users\DigiParent\Desktop\Project data\good.txt”
'IO.File.SetAttributes(“C:\Users\DigiParent\Desktop\Project data\DigitMeInfo.txt”,IO.FileAttributes.Hidden)
Dim timeChecker作为新的System.IO.StreamWriter(timeinfo,True)
timeChecker.Close()
Dim readertime作为新System.IO.StreamReader(timeinfo,Encoding.Default)
Dim texttime As String=readertime.ReadToEnd
readertime.Close()
如果texttime=“”,则
Dim timeobjWriter作为新System.IO.StreamWriter(timeinfo,True)
timeobjWriter.Write(“,,,”)
timeobjWriter.Close()
如果结束
Dim启动为String=“C:\Users\DigiParent\Desktop\Project data\good.txt”
Dim reader作为新System.IO.StreamReader(启动、编码、默认)
Dim数据为字符串=reader.ReadToEnd
文本文件(6)作为字符串
aryTextFile=data.Split(“,”)
Mondayt=aryTextFile(0)
Tuesdayt=aryTextFile(1)
Wendsdayt=aryTextFile(2)
星期四=aryTextFile(3)
Fridayt=aryTextFile(4)
'
'在周六和周日启用此选项
'
'Saturdayt=aryTextFile(5)
'Sundayt=aryTextFile(6)
reader.Close()
' //
' //
“//完成读取器
' //
端接头
私有子面板2u MouseMove(发送者作为对象,e作为MouseEventArgs)处理Panel2.MouseMove、time.MouseMove、timeup.MouseMove
如果unstop=True,则
如果e.Button=Windows.Forms.MouseButtons.Left,则
NewPoint=Control.MousePosition
NewPoint.X-=(X)
NewPoint.Y-=(Y)
Me.Location=NewPoint
如果结束
如果结束
端接头
私有子面板2u MouseDown(发送方作为对象,e作为MouseEventArgs)处理面板2.MouseDown、time.MouseDown、timeup.MouseDown
如果unstop=True,则
X=Control.MousePosition.X-Me.Location.X
Y=Control.MousePosition.Y-Me.Location.Y
如果结束
端接头
私有子Timer1\u Tick(发送方作为对象,e作为事件参数)处理Timer1.Tick
左上下小时数-=40
NumericUpDownmin.Left-=40
数字上下秒左-=29'25
Hourstxt.Left-=40
分钟文本左-=30
第二个文本左-=30
面板1.左-=30
RadioButton2.左-=30
RadioButton1.左-=30
标签4.左-=30
标签5.左-=30
按钮4.左-=30
时间。左-=30
timeup.Left-=30
如果RadioButton1.Location=RadioButton5.Location,则
计时器1.Stop()
其他的
如果结束
如果我身高<265那么
Me.Height=Me.Height+1
如果结束
端接头
私有子按钮1\u单击(发送者作为对象,e作为事件参数)处理按钮1。单击
more.Visible=False
updateb.Visible=False
feedbackb.Visible=False
Timer1.Start()
按钮1.可见=错误
端接头
私有子RadioButton5\u CheckedChanged(发送方作为对象,e作为事件参数)处理RadioButton5.CheckedChanged
端接头
私有子按钮4\u单击(作为对象,作为事件参数)处理按钮4。单击
My.Settings.Data=True
如果RadioButton6.Checked=True,则
My.Settings.unstitable=真
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
身高=149
其他的
My.Settings.unstitable=False
如果结束
如果RadioButton1.Checked=True,则
My.Settings.Shutdown=True
checkoff=True
'系统.诊断.过程.开始(“关闭”、“/s”)
其他的
My.Settings.Shutdown=False
如果结束
vhrs=数值上升下降小时数
vmin=数值上下限最小值
vsec=数值上升下降秒值
My.Settings.hours=vhrs
My.Settings.min=vmin
My.Settings.second=vsec
PictureBox1.Dock=DockStyle.None
PictureBox1.Visible=False
starttime.Start()
realTimer.Start()
端接头
公共小时数为整数“小时数”
公共最小值为整数“分钟数”
公共秒为整数“秒数”
公共函数GetTime(时间为整数)为字符串
“秒”
秒=时间模60
“分钟”
分钟=((时间-秒)/60)模60
“小时”
小时=((时间-(秒+(分钟*60)))/3600)模60
返回格式(小时,“00”)&“&”格式(分钟,“00”)&“&”格式(秒,“00”)
端函数
Private Sub realTimer_Tick(发送者作为对象,e作为事件参数)处理realTimer.Tick
秒=秒+1
time.Text=GetTime(秒)
“现在
如果最小值>=vmin,小时数>=vhrs,秒数>=vsec,则
胆碱酯酶
Module Module1
Public Sub Main()
Application.Run(New Watchdog)
End Sub
End Module
Public Class Watchdog
Inherits ApplicationContext
Private AppToWatch As String
Private FullPath As String = "C:\WINDOWS\system32\calc.exe"
Private WithEvents P As Process
Public Sub New()
AppToWatch = System.IO.Path.GetFileNameWithoutExtension(FullPath)
Dim PS() As Process = Process.GetProcessesByName(AppToWatch)
If PS.Length = 0 Then
StartIt()
Else
P = PS(0)
P.EnableRaisingEvents = True
End If
End Sub
Private Sub P_Exited(sender As Object, e As EventArgs) Handles P.Exited
StartIt()
End Sub
Private Sub StartIt()
P = Process.Start(FullPath)
P.EnableRaisingEvents = True
End Sub
End Class