Sunday, June 2, 2013

Create you own shutdown management control system


Public Class Form2
    Dim i, j As Integer
    Dim TM As Date
    Private Declare Function LockWorkStation Lib "user32.dll" () As Long
    Private Declare Function ShutDownDialog Lib "shell32.all" Alias "#60" (ByVal any As Long)

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Text = "Shutdown Manager - " + TimeOfDay
        Me.Label3.Text = "ពេលវេលាបច្ចុប្បន្ន៖ " + TimeOfDay
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer2.Interval = 10000
        Timer1.Enabled = True

        For Me.i = 0 To 23 Step 1
            cboHourse.Items.Add(i)
        Next

        For Me.j = 0 To 60 Step 1
            cboMinutes.Items.Add(j)
        Next
    End Sub

    Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
        cmdStart.Text = "កំពុងដំណើរការ"
        If Val(cboHourse.Text) > 0 Or Val(cboMinutes.Text) > 0 Then
            TM = Now.AddMinutes(Val(cboHourse.Text) * 60 + Val(cboMinutes.Text))
            Timer2.Enabled = True
            lblStatuse.Text = "កំណត់ពេលវេលាគឺ៖ " + TM

        Else
            lblStatuse.Text = "សូមបញ្ចូលពេលវេលាជាមុន"
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If Now > TM Then
            If RdoLogOff.Checked = True Then
                Shell("shutdown -l")
            End If

            If RdoRestart.Checked = True Then
                Shell("shutdown -r")
            End If

            If RdoShutDown.Checked = True Then
                Shell("shutdown -s")
            End If

            If RdoLockPC.Checked = True Then
                LockWorkStation()
            End If

            If RdoHybernate.Checked = True Then
                Shell("shutdown -h")
            End If

            Timer1.Enabled = False
            Timer2.Enabled = False
        End If
    End Sub

    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        cmdStart.Text = "Start"
        Timer2.Enabled = False
        lblStatuse.Text = "ប្រព័ន្ធអាចចាប់ផ្តើមជាថ្មីបាន!"
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        End
    End Sub
End Class

No comments:

Post a Comment