2010年3月10日 星期三

累計不連續上網秒數自動關瀏覽器

imageimage
Import s System.Text
Imports System.IO.Ports
Public Class Form1
    Dim proc As System.Diagnostics.Process
    Dim accSec As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer2.Enabled = True
        Timer2.Interval = 1000
        Me.Text = "累計不連續上網秒數自動關瀏覽器"
        Label1.Text = "打開IE瀏覽器後,計時器會自動起動"
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        accSec = accSec + 1
        Label1.Text = "時間累計:" & accSec & "秒"
        My.Computer.FileSystem.WriteAllText("C:\sec.txt", accSec, False)
        If accSec >= 60 Then
            For Each proc In System.Diagnostics.Process.GetProcesses
                If LCase(proc.ProcessName) Like "*iexplore*" Then
                    proc.Kill()
                End If
            Next
        End If
    End Sub
    Sub startclock()
        Dim fileContents As String
        fileContents = My.Computer.FileSystem.ReadAllText("C:\sec.txt")
        accSec = Val(fileContents)
        Timer1.Interval = 1000
        Timer1.Enabled = True
    End Sub
    Sub stopclock()
        My.Computer.FileSystem.WriteAllText("C:\sec.txt", accSec, False)
        'Timer1.Interval = 1000
        Timer1.Enabled = False
    End Sub
    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        Dim isFound = False
        For Each proc In System.Diagnostics.Process.GetProcesses
            If LCase(proc.ProcessName) Like "*iexplore*" Then
                startclock()
                isFound = True
            End If
        Next
        If isFound = False Then stopclock()
    End Sub
End Class

沒有留言: