Option ExplicitPrivate Declare Function RtlAdjustPrivilege Lib "ntdll" (ByVal Privilege As Long, ByVal Newvalue As Long, ByVal NewThread As Long, Oldvalue As Long) As Long Private Declare Function NtShutdownSystem Lib "ntdll" (ByVal ShutdownAction As Long) As Long Private Const SE_SHUTDOWN_PRIVILEGE As Long = 19& Private Const SHUTDOWN As Long = 0& Private Const RESTART As Long = 1& Private Const POWEROFF As Long = 2& 'Private Const LOGOFF_QUIET As Long = H10& 'Private Const LOGOFF_NORMAL As Long = H1& Private Sub Command1_Click(cIndex As Integer) If cIndex = 0 Then RtlAdjustPrivilege SE_SHUTDOWN_PRIVILEGE, 1, 0, 0 NtShutdownSystem SHUTDOWN Or RESTART End If If cIndex = 1 Then RtlAdjustPrivilege SE_SHUTDOWN_PRIVILEGE, 1, 0, 0 NtShutdownSystem SHUTDOWN Or POWEROFF End If If cIndex = 2 Then Unload Me End End If End SubPrivate Sub Form_Load() Command1(0).Caption = "快速启动计算机" Command1(1).Caption = "快速关闭计算机" Command1(2).Caption = "退 出" End Sub
Private Declare Function NtShutdownSystem Lib "ntdll" (ByVal ShutdownAction As Long) As Long
Private Const SE_SHUTDOWN_PRIVILEGE As Long = 19&
Private Const SHUTDOWN As Long = 0&
Private Const RESTART As Long = 1&
Private Const POWEROFF As Long = 2&
'Private Const LOGOFF_QUIET As Long = H10&
'Private Const LOGOFF_NORMAL As Long = H1&
Private Sub Command1_Click(cIndex As Integer)
If cIndex = 0 Then
RtlAdjustPrivilege SE_SHUTDOWN_PRIVILEGE, 1, 0, 0
NtShutdownSystem SHUTDOWN Or RESTART
End If
If cIndex = 1 Then
RtlAdjustPrivilege SE_SHUTDOWN_PRIVILEGE, 1, 0, 0
NtShutdownSystem SHUTDOWN Or POWEROFF
End If
If cIndex = 2 Then
Unload Me
End
End If
End SubPrivate Sub Form_Load()
Command1(0).Caption = "快速启动计算机"
Command1(1).Caption = "快速关闭计算机"
Command1(2).Caption = "退 出"
End Sub
那就用下面这个微软没有公开的API函数(不需要提升权限了):[url=http://blog.csdn.net/chenjl1031/article/details/7305337][/rul]
那就用下面这个微软没有公开的API函数(不需要提升权限了):http://blog.csdn.net/chenjl1031/article/details/7305337
Call SHShutDownDialog(0) '相当于鼠标按“开始”,再按“关闭计算机”,将调用系统关闭计算机对话框
End Sub 这句可能有点问题。测试系统:win7 64位
你复制程序的时候,API函数后面如果有空格要删除,复制粘贴程序经常会遇到这个问题。
Win7没有关闭Windows对话框,所以Call SHShutDownDialog(0)无效,但不会出错。