最近在網上搜索了一些關於實現關機
本篇文章具有一定的基礎性和廣泛的實用性
本文所使用的編程環境是Microsoft Visual Studio
具體步驟如下
現在我們就需要為程序加上一個定時器了
以上界面工作基本完成現在需要輸入代碼了
雙擊窗體進入常規
CODE
Imports System
Imports Microsoft
Public Class Form
Friend Shared Function GetCurrentProcess() As IntPtr
End Function
Friend Shared Function OpenProcessToken(ByVal h As IntPtr
ByVal acc As Integer
End Function
Friend Shared Function LookupPrivilegeValue(ByVal host As String
ByVal name As String
End Function
Friend Shared Function AdjustTokenPrivileges(ByVal htok As IntPtr
ByVal disall As Boolean
ByVal len As Integer
ByVal relen As IntPtr) As Boolean
End Function
Friend Shared Function ExitWindowsEx(ByVal flg As Integer
ByVal rea As Integer) As Boolean
End Function
Friend Const SE_PRIVILEGE_ENABLED As Integer = &H
Friend Const TOKEN_QUERY As Integer = &H
Friend Const TOKEN_ADJUST_PRIVILEGES As Integer = &H
Friend Const SE_SHUTDOWN_NAME As String =
Friend Const EWX_LOGOFF As Integer = &H
Friend Const EWX_SHUTDOWN As Integer = &H
Friend Const EWX_REBOOT As Integer = &H
Friend Const EWX_FORCE As Integer = &H
Friend Const EWX_POWEROFF As Integer = &H
Friend Const EWX_FORCEIFHUNG As Integer = &H
Friend Structure TokPriv
Public Count As Integer
Public Luid As Long
Public Attr As Integer
End Structure
Private Shared Sub DoExitWin(ByVal flg As Integer)
Dim xc As Boolean
Dim tp As TokPriv
Dim hproc As IntPtr = GetCurrentProcess()
Dim htok As IntPtr = IntPtr
xc = OpenProcessToken(hproc
tp
tp
tp
xc = LookupPrivilegeValue(Nothing
xc = AdjustTokenPrivileges(htok
xc = ExitWindowsEx(flg
End Sub
Public Shared Sub Reboot()
DoExitWin((EWX_FORCE Or EWX_REBOOT))
End Sub
Public Shared Sub PowerOff()
DoExitWin((EWX_FORCE Or EWX_POWEROFF))
End Sub
Public Shared Sub LogoOff()
DoExitWin((EWX_FORCE Or EWX_LOGOFF))
End Sub
Dim entTime As Object
Dim xianzaiTime As Object
Dim startTime As Object
注銷button
Private Sub Button
ByVal e As System
LogoOff()
End Sub
雙擊重新啟動按鈕button
Private Sub Button
ByVal e As System
Reboot()
End Sub
雙擊關閉計算機按鈕button
Private Sub Button
ByVal e As System
startTime = TimeOfDay
If Not IsDate(TextBox
MsgBox(
Else
entTime = TimeValue(TextBox
End If
Timer
Me
End Sub
如圖
圖
雙擊timer
圖
輸入代碼
Private Sub Timer
ByVal e As System
xianzaiTime = TimeOfDay
If RadioButton
If DateDiff(Microsoft
xianzaiTime
End If
End If
PowerOff()
End Sub
好了
先創建一個Label控件吧
圖
接下來需要輸入代碼了
進入Public Class Form
代碼
Private Declare Function ShellExecute Lib
Alias
ByVal lpOperation As String
ByVal lpParameters As String
ByVal nShowCmd As Integer) As Integer
如圖
圖
雙擊剛才添加的label屬性text:(天極網開發頻道)中輸入以下代碼
Private Sub Label
ByVal e As System
ShellExecute(
End Sub
End Class
OK!全部搞定
圖
From:http://tw.wingwit.com/Article/program/net/201311/12366.html