| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 992 人关注过本帖
标题:windows2000 xp 关机函数
取消只看楼主 加入收藏
guanqiang
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-11-18
收藏
 问题点数:0 回复次数:0 
windows2000 xp 关机函数
Private Enum HowExitConst
EWX_LOGOFF = 0 ''注销
EWX_SHUTDOWN = 1 ''关机
EWX_REBOOT = 2 ''重新启动
EWX_FORCE = 4 '强制关机
End Enum
Const TOKEN_ADJUST_PRIVILEGES = &H20
Const TOKEN_QUERY = &H8
Const SE_PRIVILEGE_ENABLED = &H2
Const ANYSIZE_ARRAY = 1
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
Private Declare Function ExitWindowsEx Lib "User32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, lpLuid As LUID) As Long
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (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 Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As Long, ByVal DesiredAccess As Long, TokenHandle As Long) As Long
Dim method As HowExitConst
Dim Ydgqsql As String
Dim Ydgqdb As dao.Database
Dim Ydgqrs As dao.Recordset
Private Sub AdjustToken() '''获得系统授权函数,使程序有足够的优先权关机
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
Sub ExitWindowsGj() '''关机函数
method = EWX_SHUTDOWN
Call AdjustToken
Call ExitWindowsEx(method, 0)
End Sub



method = EWX_SHUTDOWN
DelAllSong.Enabled = True
ShellExecute 0, vbNullString, App.Path + "\end.bat", "", "", 0
Call AdjustToken '***关闭系统
Call ExitWindowsEx(method, 4)



method = EWX_REBOOT
DelAllSong.Enabled = True
ShellExecute 0, vbNullString, App.Path + "\end.bat", "", "", 0
Call AdjustToken '***重启系统
Call ExitWindowsEx(method, 2)
搜索更多相关主题的帖子: 函数 
2007-11-18 01:44
快速回复:windows2000 xp 关机函数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041125 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved