Excel VBA高级编程:用VBA关闭计算机的代码

2015-04-13 17:05 阅读 97 次 评论关闭

!请注意你WINDOWS的版本

*API函数声明
Declare Function ExitWindows Lib "User" (ByVal dwReturnCode As Long, ByVal wReserved As Integer) As Integer
注释:执行
Dim DUMMY
DUMMY=ExitWindows(0,0)

强制关闭计算机:用API函数ExitWindowsEx可以实现强制关机,即便是您的应用程序尚未保存文件。
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 a
a = ExitWindowsEx(EWX_LOGOFF or EWX_FORCE or EWX_SHUTDOWN, 0)
End Sub
如果将
a = ExitWindowsEx(EWX_LOGOFF or EWX_FORCE or EWX_SHUTDOWN, 0)
改换为
a = ExitWindowsEx(EWX_LOGOFF or EWX_REBOOT, 0)
即可实现强制重启计算机!

版权声明:本文著作权归原作者所有,欢迎分享本文,谢谢支持!
转载请注明:Excel VBA高级编程:用VBA关闭计算机的代码 | 猎微网

评论已关闭!