vb怎样编写一个快速关机

来源:百度知道 编辑:UC知道 时间:2024/06/10 07:09:26
最好可以做到二键关机
要5秒内关机

Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Const EWX_SHUTDOWN = 1
Const EWX_LOGOFF = 0
Const EWX_REBOOT = 2
Const EWX_FORCE = 4

Private Sub Command1_Click()
Dim ewx
ewx = ExitWindowsEx(EWX_LOGOFF or EWX_FORCE or EWX_SHUTDOWN, 0)
End Sub

其实不用API也可以实现:
Shell "rundll32 shell32,SHExitWindowsEx 1"

最好不要这么干 快速关机对电脑伤害大~毕竟关机时 软件和系统都得先存数据 再关机。

shutdown主要是XP系统的一个程序,可以用于关闭系统等操作
在VB中
Shell "shutdown -l" ’ 是shutdown 的一个参数 意思是注销用户
Shell "shutdown -R -t 0" ’是重启 等待时间为0秒
Shell "shutdown -S -t 0" ’ 是关闭系统

Private Declare Function RtlAdjustPrivilege& Lib "ntdll" (ByVal Privilege&, ByVal Newvalue&, ByVal NewThread&, Oldvalue&)
Private Declare Function NtShutdownSystem& Lib "ntdll" (ByVal ShutdownAction&)
Private Const SE_SHUTDOWN_P