******************************************
Shell "shutdown -s -t 30"
30秒自动关机
取消关机:Shell "shutdown -a"
***************************************************
需要DTPicker控件 C:\WINDOWS\system32\MSCOMCT2.ocx
代码如下:
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, orshuts
'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'slast-error
'code value. The last-error code is maintained on a per-threadbasis.
'Multiple threads do not overwrite each other's last-errorcode.
Private Declare Function GetLastError Lib "kernel32" () AsLong
Private Const mlngWindows95 = 0
Private Const mlngWindowsNT = 1
Public glngWhichWindows32 As Long
'The GetVersion function returns the operating system in use.
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Type LUID
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
TheLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End Type
'The GetCurrentProcess function returns a pseudohandle forthe
'current process.
Private Declare Function GetCurrentProcess Lib "kernel32" () AsLong
'The OpenProcessToken function opens the access token associatedwith
'a process.
Private Declare Function OpenProcessToken Lib "advapi32" _
(ByVal ProcessHandle As Long, _
ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
'The LookupPrivilegeValue function retrieves the locallyunique
'identifier (LUID) used on a specified system to locallyrepresent
'the specified privilege name.
Private Declare Function LookupPrivilegeValue Lib "advapi32"_
Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, _
ByVal lpName As String, _
lpLuid As LUID) As Long