16位Windows用ExitWindows() API函数,而32位Windows则用ExitWindowsEx().32位版本比16位版本多了更多的控制及选项,包括注销及关机。 Declare Function ExitWindows Lib "user" (ByVal uFlags As Long, ByVal _
dwReserved As integer) As integer
Const EW_REBOOTSYSTEM = &H43
Const EW_RESTARTWINDOWS = &H42 Sub Command1_Click() Dim rVal As Integer rVal = ExitWindows(EW_REBOOTSYSTEM, 0) End Sub ***** 32位的例子 *****
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4 Private Sub Command1_Click() Dim rVal As Long rVal = ExitWindowsEx(EWX_SHUTDOWN, 0&) End Sub
dwReserved As integer) As integer
Const EW_REBOOTSYSTEM = &H43
Const EW_RESTARTWINDOWS = &H42 Sub Command1_Click() Dim rVal As Integer rVal = ExitWindows(EW_REBOOTSYSTEM, 0) End Sub ***** 32位的例子 *****
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, _
ByVal dwReserved As Long) As Long
Private Const EWX_LOGOFF = 0
Private Const EWX_SHUTDOWN = 1
Private Const EWX_REBOOT = 2
Private Const EWX_FORCE = 4 Private Sub Command1_Click() Dim rVal As Long rVal = ExitWindowsEx(EWX_SHUTDOWN, 0&) End Sub
解决方案 »
- VB调用DLL中的函数
- 如何用API控制NTFS分区目录的安全?
- 如何让DateReport打印时一行显示三条记录
- 利listview
- 怎么用 dependency walker!!我不会看啊!!!请高手赐教!!!
- 如何将整数数字转换为英文写法?急!!!
- 如何将一个很大的double型十进制数转换为十六进制数?(高分悬赏)
- 急:我的vb6系统出了问题,重装时无法注册msaddinndr.dll!!!(多谢 多谢)
- VB和access2000使用data控件是不是连不上。
- 分数很多!!在VB中用SQL语句查询的方法?
- 如何使datagrid控件每增加一行时,箭头都指向最后一行,即新增的那行?
- 请问如何获得封闭的不规则图形的面积?
Exitwindows 1,1关机
exitwindows 2,1重启
ExitWindows 0,1注消
可能实现
UsedPart As Long
IgnoredForNowHigh32BitPart As Long
End TypePrivate Type TOKEN_PRIVILEGES
PrivilegeCount As Long
TheLuid As LUID
Attributes As Long
End TypePrivate Const EWX_SHUTDOWN As Long = 1
Private Const EWX_FORCE As Long = 4
Private Const EWX_REBOOT = 2
Private Const EWX_POWEROFF = 8Private Declare Function ExitWindowsEx Lib "user32" (ByVal _
dwOptions As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function OpenProcessToken Lib "advapi32" (ByVal _
ProcessHandle As Long, _
ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32" _
Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, ByVal lpName As String, lpLuid _
As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32" _
(ByVal TokenHandle As Long, _
ByVal DisableAllPrivileges As Long, NewState As TOKEN_PRIVILEGES _
, ByVal BufferLength As Long, _
PreviousState As TOKEN_PRIVILEGES, ReturnLength As Long) As Long
Public Sub Main()
Dim I As Long
I = StandardShutdown()
End SubPublic Function StandardShutdown() As Long'Function to perform a standard shutdown of Windows. Needs to be a
'global function since it is called from more than one procedure.
AdjustToken
StandardShutdown = ExitWindowsEx(EWX_SHUTDOWN Or EWX_FORCE Or EWX_POWEROFF, 0&)End Function
Private Sub AdjustToken()
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Dim hdlProcessHandle As Long
Dim hdlTokenHandle As Long
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Long hdlProcessHandle = GetCurrentProcess()
OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or _
TOKEN_QUERY), hdlTokenHandle ' Get the LUID for shutdown privilege
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid tkp.PrivilegeCount = 1 ' One privilege to set
tkp.TheLuid = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED' Enable the shutdown privilege in the access token of this process
AdjustTokenPrivileges hdlTokenHandle, False, _
tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeededEnd Sub