'暈!我剛剛才做了一個,把代碼給你。(怎么這么巧啊?)
'你需要畫一個timer,名字叫timer1,然后把代碼復制就可以了。
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, or shuts
'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's last-error
'隨緣測de value. The last-error 隨緣測de is maintained on a per-thread basis.
'Multiple threads do not overwrite each other's last-error 隨緣測de.
Private Declare Function GetLastError 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 for the
'current process.
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
'The OpenProcessToken function opens the access token associated with
'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 locally unique
'identifier (LUID) used on a specified system to locally represent
'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
'The AdjustTokenPrivileges function enables or disables privileges
'in the specified access token. Enabling or disabling privileges
'in an access token requires TOKEN_ADJUST_PRIVILEGES access.
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 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 Sub AdjustToken()
'
**'* This procere sets the proper privileges to allow a log off or a
'* shut down to occur under Windows NT.
'
**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
'Set the error 隨緣測de of the last thread to zero using the
'SetLast Error function. Do this so that the GetLastError
'function does not return a value other than zero for no
'apparent reason.
SetLastError 0
'Use the GetCurrentProcess function to set the hdlProcessHandle
'variable.
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, _
lBufferNeeded
End Sub
Private Sub Form_Load()
'
**'* When the project starts, check the operating system used by
'* calling the GetVersion function.
'
**Dim lngVersion As Long
lngVersion = GetVersion()
If ((lngVersion And &H80000000) = 0) Then
glngWhichWindows32 = mlngWindowsNT
Else
glngWhichWindows32 = mlngWindows95
End If
End Sub
Private Sub Timer1_Timer()
V = MsgBox("確認要關機嗎?", vbYesNo + vbQuestion, "???")
If V = vbYes Then
If glngWhichWindows32 = mlngWindowsNT Then
AdjustToken
End If
ExitWindowsEx (EWX_SHUTDOWN Or EWX_FORCE Or EWX_POWEROFF), 0
End If
End Sub
檀江筠
檀江快
檀江廈
檀江賓
檀江裎
檀江蓬
檀江東
檀江芹
檀江危
檀江棠
檀江狀
檀江皎
檀江俠
檀江沈
檀江戌
檀江銓
檀江珩
檀江蠶
檀江守
檀江鈉
檀江芊
檀江商
檀江錳
檀江乃
檀江萬
江妗語 江雨淥 江海誠 江木明 江建真 江俊宏 江淼賀 江宇斌 江世恒 江太涵 江叢楠 江偉振 江桀暉 江學罡 江義丁 江嘉宸 江東洲 江彥能 江文潼 江佩翰 江正恒 江子文 江彥亮 江添宜 江叔涵 江嘉鋒 江通濤 江駿陽 江鴻博 江天涵 江世良 江芷宛 江亞康 江振芯 江凇瑞 江庭權 江秉華 江子昊 江鈺焯 江蓀鑫 江仡貞 江涵陽 江采濤 江梓武 江昭蘇 江政宇 江從鵬 江東霖 江焜陽 江啟道 江明州 江雅琪 江思平 江驁欞 江銘鋒 江嘉川 江高鑫 江鴻喬 江艾迪 江熙然 江明賓 江楚彬 江秋凡 江宛明 江顯銘 江景越 江效宇 江建都 江琦軒 江東勝 江智香 江芮名 江運浩 江澤偉 江光法 江維宇 江淋杰 江令耀 江千鍵 江珩峰 江新偉 江凌灣 江成民 江宗萬 江加宏 江羽林 江俊源 江韶果 江智里 江啟郡 江向彥 江方心 江生倪 江彥明 江櫓燊 江玉彬 江思權 江止涵 江宇伊 江偉鴻
女孩
江培永 江沼樂 江懋晴 江熠涵 江宇諭 江芝璐 江艷晨 江利英 江夢蓮 江冬琴 江海陽 江土巖 江倩然 江一婷 江采臻 江淑欄 江粲紅 江云儒 江春瀅 江譽鎣 江慧宜 江永洛 江倩華 江仙范 江俊爽 江錦榮 江愛雯 江元菲 江吳志 江小瑤 江璐焉 江若睿 江一銘 江培睿 江夢萍 江金婷 江瀟氏 江怡航 江卓鳴 江藝弘 江朝瀚 江思鑫 江鴻儀 江詩雙 江善思 江希坤 江秉茵 江厲月 江遠妃 江麗華 江一嵐 江培凡 江若杰 江雨怡 江枳柯 江鍵琳 江阿渲 江彤萱 江思茹 江詩利 江高艾 江博娜 江彥娟 江紹怡 江靖毛 江小梅 江雅桐 江晨諾 江曉暄 江希凡 江雨水 江婷軒 江美莉 江天菡 江秀怡 江衍桂 江錦洹 江青娥 江博佳 江海云 江麗蕊 江澤宇 江曉嫣 江于葉 江晨賢 江春寒 江瀾宇 江木平 江范雅 江蘆鑫 江紅澄 江苗仝 江亞雅 江亓亨 江天明 江藝翌 江思娟 江欣夏 江芳夢 江愛溢
(责任编辑:寶寶起名)