- ©«¤l
- 109
- ¥DÃD
- 2
- ºëµØ
- 0
- ¿n¤À
- 114
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7 Win10
- ³nÅ骩¥»
- Office 2019 WPS
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ²`¦`
- µù¥U®É¶¡
- 2013-2-2
- ³Ì«áµn¿ý
- 2024-11-6
|
¦^´_ 1# spermbank
ª`·NExitWindows³oÓµ{¦¡ªº½Õ¥Î°Ñ¼Æ¡A¥i¥H¤À§O¥Î¥H实现Ãö³¬¹q·½¡B«·s±Ò°ÊWindows©Î¬Oµn¥X·í«e¥Î¤á¡C- #If VBA7 Then
- Private Declare PtrSafe Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long
- Private Declare PtrSafe Function GetLastError Lib "KERNEL32" () As Long
- Private Declare PtrSafe Function GetCurrentProcess Lib "KERNEL32" () As Long
- Private Declare PtrSafe Function OpenProcessToken Lib "advapi32" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
- Private Declare PtrSafe Function LookupPrivilegeValue Lib "advapi32" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
- Private Declare PtrSafe 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
- Private Declare PtrSafe Sub SetLastError Lib "KERNEL32" (ByVal dwErrCode As Long)
- Private Declare PtrSafe Function GetVersion Lib "KERNEL32" () As Long
- #Else
- Private Declare Function ExitWindowsEx Lib "user32" (ByVal dwOptions As Long, ByVal dwReserved As Long) As Long
- Private Declare Function GetLastError Lib "KERNEL32" () 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
- Private Declare Sub SetLastError Lib "KERNEL32" (ByVal dwErrCode As Long)
- Private Declare Function GetVersion Lib "KERNEL32" () As Long
- #End If
- 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
- Public Enum ExitMode
- Exit_LOGOFF = 0&
- Exit_SHUTDOWN = 1&
- Exit_REBOOT = 2&
- Exit_FORCE = 4&
- Exit_POWEROFF = 8&
- Exit_FORCEIFHUNG = &H10&
- Exit_RESTARTAPPS = &H40&
- End Enum
- Public Function ExitWindows(Optional ByVal ExitMode As ExitMode = Exit_SHUTDOWN Or Exit_FORCE) As Long
- '********************************************************************
- '* ³oÓµ{¦¡¥Î¨ÓÃö³¬¡B«±Òpºâ¾÷©Î¬Oµn¥X·í«e¥Î¤á
- '********************************************************************
- 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
- Dim lngVersion As Long
-
- On Error GoTo ErrorExit
- Err.Clear
- lngVersion = GetVersion()
- If ((lngVersion And &H80000000) = 0) Then
- SetLastError 0
- hdlProcessHandle = GetCurrentProcess()
- ExitWindows = GetLastError: If ExitWindows Then Exit Function
- OpenProcessToken hdlProcessHandle, (TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY), hdlTokenHandle
- ExitWindows = GetLastError: If ExitWindows Then Exit Function
- LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
- ExitWindows = GetLastError: If ExitWindows Then Exit Function
- tkp.PrivilegeCount = 1
- tkp.TheLuid = tmpLuid
- tkp.Attributes = SE_PRIVILEGE_ENABLED
- AdjustTokenPrivileges hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded
- ExitWindows = GetLastError: If ExitWindows Then Exit Function
- End If
- If ExitWindowsEx(ExitMode, &HFFFF) = 0 Then ExitWindows = GetLastError
- Exit Function
- ErrorExit:
- ExitWindows = Err.Number
- End Function
- Sub PowerOff()
- ExitWindows Exit_POWEROFF Or Exit_FORCE
- End Sub
½Æ»s¥N½X ¤W¤@¼Ó¦^´_¤£ª¾¬°¦ó³Q½×¾Â¦Y±¼¤F¤@¥bªº¥N½X¡K¡K |
|