?? form1.frm
字號:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4260
ClientLeft = 45
ClientTop = 330
ClientWidth = 3825
LinkTopic = "Form1"
ScaleHeight = 4260
ScaleWidth = 3825
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command5
Caption = "關操作系統,并關電源"
Height = 492
Left = 750
TabIndex = 4
Top = 3480
Width = 2292
End
Begin VB.CommandButton Command4
Caption = "強制關機"
Height = 492
Left = 720
TabIndex = 3
Top = 2640
Width = 2292
End
Begin VB.CommandButton Command3
Caption = "關閉操作系統、并重起"
Height = 492
Left = 720
TabIndex = 2
Top = 1800
Width = 2292
End
Begin VB.CommandButton Command2
Caption = "關閉操作系統、未關電源"
Height = 492
Left = 720
TabIndex = 1
Top = 960
Width = 2292
End
Begin VB.CommandButton Command1
Caption = "注銷"
Height = 492
Left = 720
TabIndex = 0
Top = 120
Width = 2292
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
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 = 9 '關閉操作系統、并關閉電源
Private Const ANYSIZE_ARRAY As Long = 1
'ExitWindowsEx函數可以退出登錄、關機或者重新啟動系統
Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long
Private Type LUID
lowpart As Long
highpart As Long
End Type
Private Type LUID_AND_ATTRIBUTES
pLuid As LUID
Attributes As Long
End Type
Private Type TOKEN_PRIVILEGES
PrivilegeCount As Long
Privileges(ANYSIZE_ARRAY) As LUID_AND_ATTRIBUTES
End Type
'GetCurrentProcess函數返回當前進程的一個句柄。
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
'OpenProcessToken函數打開一個進程的訪問代號。
Private Declare Function OpenProcessToken Lib "advapi32" _
(ByVal ProcessHandle As Long, _
ByVal DesiredAccess As Long, _
TokenHandle As Long) As Long
'LookupPrivilegeValue函數獲得本地唯一的標示符(LUID),用于在特定的系統中
'表示特定的優先權。
Private Declare Function LookupPrivilegeValue Lib "advapi32" _
Alias "LookupPrivilegeValueA" _
(ByVal lpSystemName As String, _
ByVal lpName As String, _
lpLuid As LUID) As Long
'AdjustTokenPrivileges函數使能或者禁用指定訪問記號的優先權。
'使能或者禁用優先權需要TOKEN_ADJUST_PRIVILEGES訪問權限。
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 Sub AdjustTokenPrivilegesForNT()
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
LookupPrivilegeValue "", "SeShutdownPrivilege", tmpLuid
tkp.PrivilegeCount = 1
tkp.Privileges(0).pLuid = tmpLuid
tkp.Privileges(0).Attributes = SE_PRIVILEGE_ENABLED
AdjustTokenPrivileges hdlTokenHandle, _
False, _
tkp, _
Len(tkpNewButIgnored), _
tkpNewButIgnored, _
lBufferNeeded
End Sub
Private Sub Command1_Click()
Dim uFlags As Long
uFlags = 0 'EWX_FORCE Or EWX_POWEROFF
AdjustTokenPrivilegesForNT
ExitWindowsEx uFlags, &HFFFF
End Sub
Private Sub Command2_Click()
Dim uFlags As Long
uFlags = 1 'EWX_FORCE Or EWX_POWEROFF
AdjustTokenPrivilegesForNT
ExitWindowsEx uFlags, &HFFFF
End Sub
Private Sub Command3_Click()
Dim uFlags As Long
uFlags = 2 'EWX_FORCE Or EWX_POWEROFF
AdjustTokenPrivilegesForNT
ExitWindowsEx uFlags, &HFFFF
End Sub
Private Sub Command4_Click()
Dim uFlags As Long
uFlags = 4 'EWX_FORCE Or EWX_POWEROFF
AdjustTokenPrivilegesForNT
ExitWindowsEx uFlags, &HFFFF
End Sub
Private Sub Command5_Click()
Dim uFlags As Long
uFlags = 9 'EWX_FORCE Or EWX_POWEROFF
AdjustTokenPrivilegesForNT
ExitWindowsEx uFlags, &HFFFF
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -