在VB下对WinXP实现关机

来源:百度知道 编辑:UC知道 时间:2024/05/26 07:17:28
不用DOS命令

FORM上设置3个commandbutton按钮,“关机”名称为“cmdShutdown”〉〉〉〉,“注销”名称为“cmdLogoff”〉〉〉〉,“重新启动”名称为“cmdReboot”

Option Explicit

Private Const EWX_LogOff As Long = 0
Private Const EWX_SHUTDOWN As Long = 1
Private Const EWX_REBOOT As Long = 2
Private Const EWX_FORCE As Long = 4
Private Const EWX_POWEROFF As Long = 8

'The ExitWindowsEx function either logs off, shuts down, or shuts
'down and restarts the system.
Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long

'The GetLastError function returns the calling thread's last-error
'code value. The last-error code is maintained on a per-thread basis.
'Multiple threads do not overwrite each other's last-error code.
Private Declare Function GetLastError Lib "kernel32" () As Long

Private Type LUID
Used