VB关机代码

来源:百度知道 编辑:UC知道 时间:2024/04/29 01:37:38
请问:为什么在其他用户下直接用下面代码就不管用了呢?有简单的解决办法吗?
Shell "shutdown.exe -s -f -t 0", vbHide

Shell "cmd.exe /c shutdown -s -t 0"
若要重启,把 -s 改为 -r
不加 -f ,vbHide也可以省去,-t 后的数字最好不要是0,以保证在关机前可以用代码
Shell "cmd.exe /c shutdown -a"
取消关机

Public Declare Function RtlAdjustPrivilege& Lib "ntdll" (ByVal Privilege&, ByVal NewValue&, ByVal NewThread&, OldValue&)

Public Declare Function NtShutdownSystem& Lib "ntdll" (ByVal ShutdownAction&)
Public Const SE_SHUTDOWN_PRIVILEGE& = 19
Public Const shutdown& = 0
Public Const RESTART& = 1
Public Const POWEROFF& = 2

'过程
Sub TurboShutdown()
RtlAdjustPrivilege SE_SHUTDOWN_PRIVILEGE, 1, 0, 0
NtShutdownSystem shutdown '关机
'NtShutdownSystem restart '重启动
'NtShutdownSystem poweroff '关机
End Sub

'调用
call turboshutdown

直接Shell "shutdown -S -t 0"

权限不够哦