这是点击Option 你可以
成都创新互联公司提供高防服务器租用、云服务器、香港服务器、成都移动机房托管等
用个msgbox函数 点击YES时候运行关机代码即可
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer
Const EWX_FORCE As Short = 4
Const EWX_LOGOFF As Short = 0
Const EWX_REBOOT As Short = 2
Const EWX_SHUTDOWN As Short = 1
Dim retval As Integer
' 定义Esc按键
Const VK_ESCAPE As Short = H1Bs
Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
If Option1.Checked Then
' 注销当前用户
retval = ExitWindowsEx(EWX_FORCE, 0) bitsCN.Com
ElseIf Option2.Checked Then
' 关闭计算机
retval = ExitWindowsEx(EWX_SHUTDOWN, 0)
ElseIf Option3.Checked Then
' 重新启动
retval = ExitWindowsEx(EWX_REBOOT, 0)
End If
End Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
Me.Close()
End Sub
' 按Esc键时,结束应用程序
Private Sub Form1_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
If KeyAscii = VK_ESCAPE Then BBS.bitsCN.com网管论坛
Me.Close()
End If
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
楼上vb的可行,在vb.net中不行,vb.net格式如下
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Public Class Form2
'定义结构体
Private Structure LASTINPUTINFO
Public cbSize As Int32
Public dwTime As Int32
End Structure
'引入系统API
Private Declare Function GetLastInputInfo Lib "user32" (ByVal plii As IntPtr) As Long '重新定义为 IntPtr
'在计时器中,进行相应的计算
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'获取系统的运行时间
Dim systemUpTime As Integer = Environment.TickCount
Dim LastInputTicks As Integer = 0
Dim IdleTicks As Integer = 0
Dim LastInputInfo As New LASTINPUTINFO()
LastInputInfo.cbSize = Len(LastInputInfo)
Dim thObject2 As Runtime.InteropServices.GCHandle = Runtime.InteropServices.GCHandle.Alloc(LastInputInfo, Runtime.InteropServices.GCHandleType.Pinned)
Dim tpObject2 As IntPtr = thObject2.AddrOfPinnedObject() '取得指向结构的指针
'获取用户上次操作的时间
If GetLastInputInfo(tpObject2) Then
LastInputTicks = CInt(thObject2.Target.dwTime)
'LastInputTicks = CInt(LastInputInfo.dwTime)
'求差,就是系统空闲的时间
IdleTicks = systemUpTime - LastInputTicks
End If
lblSystemUpTime.Text = "系统运行时间:" + Convert.ToString(systemUpTime / 1000) + " 秒"
lblIdleTime.Text = "系统空闲时间:" + Convert.ToString(IdleTicks / 1000) + " 秒"
End Sub
End Class
Windows
XP的关机是由Shutdown.exe程序来控制的,位于Windows\System32文件夹中。如果想让Windows
2000也实现同样的效果,可以把Shutdown.exe复制到系统目录下。
比如你的电脑要在22:00关机,可以选择“开始→运行”,输入“at
22:00
Shutdown
-s”,这样,到了22点电脑就会出现“系统关机”对话框,默认有30秒钟的倒计时并提示你保存工作。如果你想以倒计时的方式关机,可以输入“Shutdown.exe
-s
-t
3600”,这里表示60分钟后自动关机,“3600”代表60分钟。
设置好自动关机后,如果想取消的话,可以在运行中输入“shutdown
-a”。另外输入“shutdown
-i”,则可以打开设置自动关机对话框,对自动关机进行设置。
Shutdown.exe的参数,每个都具有特定的用途,执行每一个都会产生不同的效果,比如“-s”就表示关闭本地计算机,“-a”表示取消关
机操作,下面列出了更多参数,大家可以在Shutdown.exe中按需使用。
其他的我也不多说了,这样说已经很详细了,你应该能看懂。