16,554
社区成员
发帖
与我相关
我的任务
分享
Imports System.Threading
Module Module1
Dim myProcesses() As Process
Dim myProcess As Process
Private timer As Threading.Timer '定时器
Private bol As Boolean = True
Sub Main()
timer = New Threading.Timer(New System.Threading.TimerCallback(AddressOf Start))
timer.Change(0, 2000) '发送心跳包 间隔2秒
Console.ReadKey()
End Sub
Private Function Start()
'心跳
If Format(Now(), "HH:mm") = "15:19" Then
If StopProcess() Is Nothing Then
Process.Start("C:\Windows\Notepad.EXE") ' 開啟 exe
End If
End If
End Function
Private Function StopProcess() As Process
myProcesses = Process.GetProcessesByName("Notepad")
For Each myProcess In myProcesses
Return myProcess
'myProcess.CloseMainWindow()
Next
Return Nothing
End Function
End Module
Public Class Form1
Dim myProcesses() As Process
Dim myProcess As Process
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer1.Interval = 5000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Format(Now(), "HH:mm") = "20:39" Then
If StopProcess() Is Nothing Then
Process.Start("C:\Windows\Notepad.EXE") ' 開啟 exe
End If
End If
End Sub
Private Function StopProcess() As Process
myProcesses = Process.GetProcessesByName("Notepad")
For Each myProcess In myProcesses
Return myProcess
'myProcess.CloseMainWindow()
Next
Return Nothing
End Function